更新查询

This commit is contained in:
xiaozhequ
2023-11-24 16:18:48 +08:00
parent 5b4feb45d6
commit 6d3cd19292
8 changed files with 741 additions and 680 deletions

View File

@@ -10,115 +10,115 @@ import java.util.List;
*/
@Data
public class CourseFullText {
/**id,对于原系统是kid*/
private String id;
/**es中的id*/
private String esId;
/**名称*/
private String name;
/**来源,1表来源老系统2表来源新系统*/
private Integer source;
private String keywords;
private String summary;
/**10无目录录播课20 有目录录播课30:面授课40学习项目*/
private Integer type;
/**多个时用到*/
private String types;
/**原系统的企业id,对应sass模式的字段*/
private String companyId;
/**封面图片*/
private String coverImg;
/**课程的评分*/
private Float score;
/**学习人数*/
private Integer studies;
/** 格式化学习人数 **/
private Integer studiesFormat;
private String teacher;
private String teacherCode;
/**发布时间*/
private Long publishTime;
/**课程的时长,秒*/
private Integer duration;
/**是否置顶*/
private Integer isTop;
/**置顶时间*/
private Long topTime;
/**系统的一级*/
private String sysType1;
/**系统的二级*/
private String sysType2;
/**系统的三级*/
private String sysType3;
private String sysType1;
/**系统的二级*/
private String sysType2;
/**系统的三级*/
private String sysType3;
/**课程的标签*/
private String tags;
/**
* 是否有受众
*/
private Integer isSetAudience;
/**受众受众的id,多个使用逗号分隔*/
//private String audience;
private String[] audiences;
/**资源归属*/
private String resOwner;
/**新系统无此字段*/
private Integer startTime;
/**新系统无此字段*/
private Integer endTime;
/**创建*/
private Long createdAt;
/***/
private String domainIds;
/**用于查询*/
private Integer maxDuration;
/**用于查询排序处理,1表最新2表最热不做存储*/
private Integer orderType;
/**设备 1PC端可见2移动端可见3多端可见*/
private Integer device;
/**
* 是否公开课0表非公开课1表公开课
*/
private Integer openCourse;
/**
* 是否公开0表非公开报名1表公开报名-字段需新增,按管理端需求增加
*/
private Integer openEnroll;
* 是否公开课0表非公开课1表公开课
*/
private Integer openCourse;
/**
* 是否公开0表非公开报名1表公开报名-字段需新增,按管理端需求增加
*/
private Integer openEnroll;
/**
@@ -141,4 +141,14 @@ public class CourseFullText {
* 受众
*/
private String audience;
}
/**
* 剔除的面授课id
*/
private String[] offCourseId;
/**
* 在线课id
*/
private String[] courseId;
}

View File

@@ -46,13 +46,16 @@ public class ThirdApi {
@Value("${infrasApi.dict}")
private String infarasApiUrl;
@Value("${manageApi.stu.offcourse}")
private String manageApiStu;
@Value("${audience.getOrgUsers}")
private String searchOrgUsersUrl;
//获取例外人员的id
public List<String> getUserId(){
log.info("正在获取例外人员工号");
// String s ="{\"show\":false,\"version\":\"1.1.0\",\"code\":200,\"msg\":\"请求成功!\",\"data\":{\"records\":[{\"id\":129,\"deleted\":null,\"createTime\":\"2023-10-16T10:03:25\",\"createId\":0,\"createName\":\"管理员\",\"updateTime\":\"2023-10-16T10:03:25\",\"updateId\":0,\"updateName\":\"管理员\",\"name\":\"李玉冰\",\"pid\":128,\"code\":\"00004409\",\"description\":null,\"value\":\"00004409\",\"img\":null,\"type\":1,\"level\":0,\"status\":0,\"sort\":0,\"children\":[]}],\"total\":0,\"size\":10,\"current\":1,\"orders\":[],\"id\":null,\"pid\":128,\"type\":1,\"status\":null,\"code\":null,\"name\":null,\"searchCount\":true,\"pages\":0},\"success\":true}";
String s = Optional.ofNullable(HttpRequest.get(infarasApiUrl).execute() //"current",1,"type",1,"pid",128)
String s = Optional.ofNullable(HttpRequest.get(infarasApiUrl).execute()
.body()).orElseThrow(() -> new RuntimeException("token校验失败"));
List<DictDto> dictDtos = Opt.ofBlankAble(s).map(t -> JSONUtil.toBean(t, DictResult.class)).map(DictResult::getData).orElseThrow();
List<String>userNo=new ArrayList<>();
@@ -61,9 +64,13 @@ public class ThirdApi {
}
return userDao.getListByUserNos(userNo).stream().map(User::getId).collect(Collectors.toList());
}
@Value("${audience.getOrgUsers}")
private String searchOrgUsersUrl;
//获取面授课id
public List<String>getOffCourseId(String userId,String token){
log.info("正在获取面授课id");
String s = Optional.ofNullable(HttpRequest.get(manageApiStu+"?userId="+userId).header("token", token).execute()
.body()).orElseThrow(() -> new RuntimeException("token校验失败"));
return Opt.ofBlankAble(s).map(t -> JSONUtil.toBean(t, StringResult.class)).map(StringResult::getData).orElseThrow();
}
public List<UserInfoListVo> getAllUserList(UserListParam userListParam, String token) {
log.info("获取用户:url:{}", searchOrgUsersUrl);
@@ -91,11 +98,7 @@ public class ThirdApi {
private void nextPage(UserListParam userListParam, String token, List<UserInfoListVo> userInfoLists, UserInfoListRootBean.ResultData t) {
log.info("nextPage 1 获取用户:" + userListParam + ",TotalPage=" + t.getTotalPage());
if (t.getTotalPage() == 0){
t.setTotalPage((int)Math.ceil(Double.parseDouble(String.valueOf(t.getTotal()))/Double.parseDouble(String.valueOf(userListParam.getPageSize()))));
}
log.info("nextPage 2 获取用户:" + userListParam + ",TotalPage=" + t.getTotalPage());
log.info("nextPage 获取用户--" + userListParam.getPageNo());
if (t.getTotalPage() > userListParam.getPageNo()) {
REQUEST_TASK.submit(() -> IntStream.range(userListParam.getPageNo(), t.getTotalPage()).parallel().forEach(i -> getAllUserList(userListParam.withPageNo(i + 1), token, userInfoLists))).join();
}

View File

@@ -0,0 +1,15 @@
package com.xboe.api.vo;
import com.xboe.module.dict.entity.DictDto;
import lombok.Data;
import java.util.List;
@Data
public class StringResult {
private Boolean show;
private String version;
private String code;
private String msg;
private List<String> data;
private String success;
}

View File

@@ -6,14 +6,8 @@ import java.util.List;
import java.util.stream.Collectors;
import com.xboe.api.ThirdApi;
import com.xboe.common.utils.StringUtil;
import com.xboe.module.boecase.dao.CasesRecordDao;
import com.xboe.old.dto.OrganizationDto;
import com.xboe.system.organization.api.OrganizationApi;
import com.xboe.system.organization.entity.Organization;
import com.xboe.school.study.service.IStudyCourseService;
import com.xboe.system.organization.service.IOrganizationService;
import com.xboe.system.organization.service.impl.OrganizationServiceImpl;
import com.xboe.system.user.dao.UserDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -40,46 +34,50 @@ import com.xboe.module.course.service.ICourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@Slf4j
@RestController
@RequestMapping(value="/xboe/m/course/fulltext")
public class CourseFullTextApi extends ApiBaseController{
@Autowired
ICourseService courseService;
@Autowired
ICourseTeacherService courseTeacherService;
@Autowired
ICourseContentService ccourseService;
@Autowired(required = false)
ICourseFullTextSearch fullTextSearch;
@Resource
IOrganizationService organizationService;
@Resource
IStudyCourseService IStudyCourseService;
@Autowired
ThirdApi thirdApi;
/**
* 课程的初始化
* @return
*/
@GetMapping("/init")
public JsonResponse<Boolean> initAllCourse(String flag) throws Exception{
if(fullTextSearch==null) {
return error("初始化失败:未实现全文检索功能");
}
//重新创建索引,如果已经存在,不会重新建
fullTextSearch.reCreateIndex(ICourseFullTextSearch.DEFAULT_INDEX_NAME);
//提取课程信息,因为现在课程没有太多,所以一次性全部查出来,
CourseQueryDto dto =new CourseQueryDto();
dto.setPublish(true);//必须是已发布的
List<Course> clist = courseService.findList(dto);
for(Course c:clist) {
CourseFullText cft=CourseToCourseFullText.convert(c);
@@ -89,7 +87,7 @@ public class CourseFullTextApi extends ApiBaseController{
//计算课程时长
int duration=ccourseService.sumDurationByCourseId(c.getId());
cft.setDuration(duration);
//查询教师
CourseTeacherDto teacherDto = courseTeacherService.getTeacherByCourseId(c.getId());
if(teacherDto!=null && !teacherDto.getNames().isEmpty()) {
@@ -110,23 +108,23 @@ public class CourseFullTextApi extends ApiBaseController{
}else {
cft.setIsSetAudience(0);//无受众
}
String fullTextId=fullTextSearch.republish(ICourseFullTextSearch.DEFAULT_INDEX_NAME, cft,c.getFullTextId());
log.info("发布课程全文检索成功:"+fullTextId);
c.setFullTextId(fullTextId);
if(StringUtils.isNotBlank(fullTextId)) {
courseService.updateFieldById(c.getId(),"fullTextId", fullTextId);
}
}catch(Exception e) {
log.error("发布课程【"+c.getName()+"("+c.getId()+")】全文检索及更新数据库失败",e);
}
}
return success(true);
}
@PostMapping("/delete-by-id")
public JsonResponse<Boolean> deleteById(String id) throws Exception{
if(fullTextSearch==null){
@@ -145,7 +143,7 @@ public class CourseFullTextApi extends ApiBaseController{
}
@PostMapping("/republish")
public JsonResponse<Boolean> republish(String id) throws Exception{
if(fullTextSearch==null) {
return error("初始化失败:未实现全文检索功能");
}
@@ -157,13 +155,13 @@ public class CourseFullTextApi extends ApiBaseController{
if(c.getPublished()==null || !c.getPublished()) {
return error("此课程还未发布,请发布课程,不用在这里重新发布");
}
CourseFullText cft=CourseToCourseFullText.convert(c);
try {
//计算课程时长
int duration=ccourseService.sumDurationByCourseId(c.getId());
cft.setDuration(duration);
//查询教师
CourseTeacherDto teacherDto = courseTeacherService.getTeacherByCourseId(c.getId());
if(teacherDto!=null && !teacherDto.getNames().isEmpty()) {
@@ -187,14 +185,14 @@ public class CourseFullTextApi extends ApiBaseController{
}else {
cft.setIsSetAudience(0);//无受众
}
String fullTextId=fullTextSearch.republish(ICourseFullTextSearch.DEFAULT_INDEX_NAME, cft,c.getFullTextId());
log.info("发布课程全文检索成功:"+fullTextId);
c.setFullTextId(fullTextId);
if(StringUtils.isNotBlank(fullTextId)) {
courseService.updateFieldById(c.getId(),"fullTextId", fullTextId);
}
}catch(Exception e) {
log.error("发布课程【"+c.getName()+"("+c.getId()+")】全文检索及更新数据库失败",e);
return error("重新发布失败",e.getMessage());
@@ -202,8 +200,8 @@ public class CourseFullTextApi extends ApiBaseController{
return success(true);
}
/**
* 全文检索查询
* @param pager
@@ -211,17 +209,29 @@ public class CourseFullTextApi extends ApiBaseController{
* @return
*/
@PostMapping("/search")
public JsonResponse<PageList<CourseFullText>> search(Pagination pager,CourseQueryDto dto,Integer minDuration,Integer maxDuration){
//获取例外人员id
public JsonResponse<PageList<CourseFullText>> search(Pagination pager, CourseQueryDto dto, Integer minDuration, Integer maxDuration, HttpServletRequest request){
//获取例外人员id
List<String> userId = thirdApi.getUserId();
String userIds = String.join(",", userId);
// String userIds="132,123";
//获取没报名课程的id
String token = request.getHeader("Xboe-Access-Token");
if (StringUtils.isEmpty(token)) {
token = request.getHeader("token");
}
List<String> offCourseId = thirdApi.getOffCourseId(dto.getUserId(),token);
String offCourseIds = String.join(",", offCourseId);
// String offCourseIds="123.311";
//根据userId查询报名的课程
List<String>courseId=IStudyCourseService.getCourseId(dto.getUserId());
String courseIds = String.join(",", courseId);
//只是查询已发布的
dto.setPublish(true);
if(this.fullTextSearch==null) {
log.error("未实现全文检索的接口 ICourseFullTextSearch");
return badRequest("当前查询不可用,未实现检索接口");
}
CourseFullText paras=new CourseFullText();
//paras.setAudience("");//权限查询,先不处理
paras.setDuration(minDuration);
@@ -241,7 +251,13 @@ public class CourseFullTextApi extends ApiBaseController{
if(StringUtils.isNotBlank(userIds)) {
paras.setSysCreateAids(userIds.split(","));
}
if(StringUtils.isNotBlank(offCourseIds)) {
paras.setOffCourseId(offCourseIds.split(","));
}
if(StringUtils.isNotBlank(courseIds)) {
paras.setCourseId(courseIds.split(","));
}
paras.setOpenCourse(dto.getOpenCourse());
if(StringUtils.isNotBlank(dto.getOrderField())) {
if(dto.getOrderField().equals("studys")) {
@@ -252,9 +268,9 @@ public class CourseFullTextApi extends ApiBaseController{
paras.setOrderType(3);//好评
}
}
paras.setDevice(dto.getDevice());
try {
//后续会根据当前用户的资源归属查询
PageList<CourseFullText> coursePageList = fullTextSearch.search(ICourseFullTextSearch.DEFAULT_INDEX_NAME,pager.getStartRow(), pager.getPageSize(),paras);
@@ -301,12 +317,12 @@ public class CourseFullTextApi extends ApiBaseController{
}
}
return success(coursePageList);
}catch(Exception e) {
log.error("课程全文检索错误",e);
return error("查询失败",e.getMessage());
}
}
}

View File

@@ -7,72 +7,67 @@ import lombok.Data;
*/
@Data
public class CourseQueryDto {
/**
* 分隔符
*/
public static final String SEPARATE="-";
/**资源归属一级*/
/**
* 分隔符
*/
public static final String SEPARATE="-";
/**资源归属一级*/
private String resOwner1;
/**资源归属二级*/
private String resOwner2;
/**资源归属三级*/
private String resOwner3;
/**授课方式,多个使用 - 分隔*/
private String types;
/**应用场景,多个使用 - 分隔*/
private String scenes;
/**是否发布,无就是全部*/
private Boolean publish;
/**
* 是否启用
*/
private Boolean enabled;
/**创建人*/
private String createUser;
/**创建人*/
private String aid;
/**查询关键词*/
private String keyword;
/**显示设备1表pc。2表移动端*/
private Integer device;
/**系统的一级*/
private String sysType1;
/**系统的二级*/
private String sysType2;
/**系统的三级*/
private String sysType3;
/**排序字段 */
private String orderField;
/**排序顺序*/
private Boolean orderAsc;
/**companyId 主要是老系统的权限*/
private String companyId;
/**
* 置顶
*/
private Boolean topOrder;
/** 状态,多个使用 - 分隔*/
private String status;
@@ -83,10 +78,10 @@ public class CourseQueryDto {
/**课程名称*/
private String name;
/**课程类型*/
private Integer type;
/**
* 是否过滤2022年之前的数据
*/
@@ -96,7 +91,7 @@ public class CourseQueryDto {
* 学习时长
* */
private Integer studyTime;
/**
* 是否公开课0表非公开课1表公开课
*/
@@ -106,17 +101,17 @@ public class CourseQueryDto {
* 表资源归属的in查询,多个使用逗号分隔
* */
private String orgIds;
/**用户权限的查询*/
private String orgAid;
/**
* 是否是超级管理员
*/
private Boolean isSystemAdmin;
private Boolean visible;
private String refId;
private String refType;
@@ -124,4 +119,9 @@ public class CourseQueryDto {
* 创建人id
*/
private String sysCreateAids;
/**
* 登录人id
*/
private String userId;
}

View File

@@ -13,7 +13,7 @@ import com.xboe.school.study.entity.StudyCourseItem;
import com.xboe.school.study.entity.StudySignup;
public interface IStudyCourseService {
/**
* 课程自动报名,返回学习的课程
* @param signup
@@ -28,7 +28,7 @@ public interface IStudyCourseService {
* @return
*/
StudyCourse has(String courseId,String aid);
/**
* 根据课程id和账户id查询学习的课程信息
* @param courseId
@@ -36,7 +36,7 @@ public interface IStudyCourseService {
* @return
*/
StudyCourse findByCourseIdAndAid(String courseId,String aid);
/**
* 为ES初始化的处理
* @param pageIndex
@@ -44,7 +44,7 @@ public interface IStudyCourseService {
* @return
*/
PageList<StudyCourse> findByES(int pageIndex,int pageSize) throws Exception;
/**
* 分页查询课程学习记录,用户的课程学习记录
* @param pageIndex
@@ -79,7 +79,7 @@ public interface IStudyCourseService {
* 二次查询 个人/他人
* */
List<StudyCourse> ids(StudyCourseQuery studyCourseQuery);
/**
* 配合ES中二次查询显示一些信息
* @param ids
@@ -101,7 +101,8 @@ public interface IStudyCourseService {
* 查询课程最新学习记录的进度
* */
List<Object[]> progress(String aid,List<String> courseIds);
List<CourseStudyItem> findByCourseAndUsers(String courseId,List<String> aids) throws Exception;
}
List<String> getCourseId(String userId);
}

View File

@@ -1,4 +1,3 @@
package com.xboe.school.study.service.impl;
import java.time.LocalDate;
@@ -6,6 +5,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
@@ -48,19 +48,19 @@ import lombok.extern.slf4j.Slf4j;
@Service
@Transactional
public class StudyCourseServiceImpl implements IStudyCourseService{
@Autowired
StudySignupDao signupDao;
@Autowired
IStudySignupService signupService;
@Autowired
StudyCourseDao studyCourseDao;
@Autowired
CourseContentDao courseContentDao;
@Autowired
StudyCourseItemDao scItemDao;
@@ -225,7 +225,7 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
query.addFilter(FieldFilters.eqField("sc.courseId","c.id"));
query.addFilter(FieldFilters.eq("c.enabled",true));
query.addFilter(FieldFilters.eq("c.deleted",false));
query.addField("sc");
if(oc==null) {
@@ -293,11 +293,11 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
@Override
public List<StudyCourse> ids(StudyCourseQuery studyCourseQuery) {
//分两次查询,查询课程,查询学习记录
String courseHql="Select id,coverImg,score from "+Course.class.getSimpleName()+" where id in(?1)";
String studyHql="Select courseId,addTime,progress,aid from "+StudyCourse.class.getSimpleName()+" where aid=?1 and courseId in(?2)";
List<StudyCourse> rs=new ArrayList<>();
try {
List<Object[]> clist= studyCourseDao.findListFields(courseHql,studyCourseQuery.getIds());
@@ -308,7 +308,7 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
sc.setCourseId(ConvertUtil.toStr(sobjs[0]));
sc.setAddTime((LocalDateTime)sobjs[1]);
sc.setProgress(ConvertUtil.toFloat(sobjs[2]));
sc.setAid(ConvertUtil.toStr(sobjs[3]));
sc.setAid(ConvertUtil.toStr(sobjs[3]));
for(Object[] cobjs : clist) {
String cid=ConvertUtil.toStr(cobjs[0]);
if(cid!=null && cid.equals(sc.getCourseId())) {
@@ -326,9 +326,9 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
log.error("查询错误",e);
e.printStackTrace();
}
return rs;
//// List<StudyCouseDto> studyCouseDtos = new ArrayList<>();
//// QueryBuilder builder = QueryBuilder.from(StudyCourse.class.getSimpleName()+" sc,"+ Course.class.getSimpleName()+" c");
//// builder.addFilter(FieldFilters.eqField("sc.courseId","c.id"));
@@ -434,7 +434,7 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
//分两次查询,查询课程,查询学习记录
String courseHql="Select id,coverImg,score,name,sysType1,sysType2,sysType3,deleted,enabled from "+Course.class.getSimpleName()+" where id in(?1)";
String studyHql="Select courseId,addTime,progress,aid from "+StudyCourse.class.getSimpleName()+" where aid in(?1) and courseId in(?2)";
List<StudyCourseSimple> rs=new ArrayList<>();
try {
List<Object[]> clist= studyCourseDao.findListFields(courseHql,studyCourseQuery.getIds());
@@ -447,7 +447,7 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
sc.setAddTime((LocalDateTime)sobjs[1]);
sc.setProgress(ConvertUtil.toFloat(sobjs[2]));
sc.setAid(ConvertUtil.toStr(sobjs[3]));
for(Object[] cobjs : clist) {
String cid=ConvertUtil.toStr(cobjs[0]);
if(cid!=null && cid.equals(sc.getCourseId())) {
@@ -492,16 +492,16 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
sc.setEnabled(ConvertUtil.toBool(cobjs[8]));
rs.add(sc);
}
}
}catch(Exception e) {
log.error("查询错误",e);
e.printStackTrace();
}
return rs;
//当前先这样查询,以后要修改,只查询需要的字段,另外 ,需要按课程分组,不然一门课程会查出很多记录出来
// QueryBuilder builder = QueryBuilder.from(StudyCourse.class.getSimpleName()+" sc,"+ Course.class.getSimpleName()+" c");
// builder.addFilter(FieldFilters.eqField("sc.courseId","c.id"));
@@ -641,7 +641,7 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
@Override
public StudyCourse autoSignup(StudySignup signup) {
signup.setSignType(StudySignup.SIGNTYPE_SELF);
StudyCourse sc=signupService.addSignup(signup);
//更新课程学习人数
@@ -675,7 +675,7 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
@Override
public List<CourseStudyItem> findByCourseAndUsers(String courseId, List<String> aids) throws Exception {
QueryBuilder query=QueryBuilder.from(StudyCourse.class.getSimpleName()+" sc,"+ Course.class.getSimpleName()+" c");
query.addFields("sc.id","sc.aid","sc.aname","sc.progress","sc.status","sc.addTime");
query.addFields("c.id","c.name","c.sysType1","c.sysType2","c.sysType3","sc.finishTime");
@@ -693,7 +693,7 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
item.setStudentName((String)objs[2]);
item.setProgress((Float)objs[3]);
item.setStatus((Integer)objs[4]);
item.setStartTime((LocalDateTime)objs[5]);
item.setCourseId((String)objs[6]);
item.setCourseName((String)objs[7]);
@@ -703,13 +703,18 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
item.setFinishTime((LocalDateTime)objs[11]);
rslist.add(item);
}
return rslist;
}
@Override
public List<String> getCourseId(String userId) {
return studyCourseDao.findList(FieldFilters.eq("aid", userId)).stream().map(StudyCourse::getCourseId).collect(Collectors.toList());
}
@Override
public List<StudyCourse> findByIds(List<String> ids) {
return studyCourseDao.findList(FieldFilters.in("id", ids));
}
}
}