|
|
|
@ -5,22 +5,27 @@ import cn.hutool.json.JSONArray;
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.tz.platform.common.core.api.ZhiYunApi;
|
|
|
|
|
import com.tz.platform.common.core.bo.Answer;
|
|
|
|
|
import com.tz.platform.common.core.config.SystemUtil;
|
|
|
|
|
import com.tz.platform.common.core.enmus.UserTypeEnum;
|
|
|
|
|
import com.tz.platform.common.core.tools.StrUtil;
|
|
|
|
|
import com.tz.platform.entity.User;
|
|
|
|
|
import com.tz.platform.feign.IFeignGrade;
|
|
|
|
|
import com.tz.platform.feign.IFeignSchool;
|
|
|
|
|
import com.tz.platform.feign.exam.IFeignCourse;
|
|
|
|
|
import com.tz.platform.feign.exam.IFeignQuestion;
|
|
|
|
|
import com.tz.platform.feign.exam.vo.CourseVO;
|
|
|
|
|
import com.tz.platform.feign.exam.vo.QuestionVo;
|
|
|
|
|
import com.tz.platform.feign.vo.GradeVo;
|
|
|
|
|
import com.tz.platform.feign.vo.SchoolVo;
|
|
|
|
|
import com.tz.platform.repository.UserDao;
|
|
|
|
|
import org.apache.commons.collections4.list.GrowthList;
|
|
|
|
|
import org.checkerframework.checker.units.qual.A;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
public class ZhiyunAccountBiz {
|
|
|
|
@ -32,6 +37,14 @@ public class ZhiyunAccountBiz {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IFeignGrade feignGrade ;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IFeignCourse feignCourse;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IFeignQuestion feignQuestion;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserDao userDao;
|
|
|
|
|
|
|
|
|
@ -58,19 +71,148 @@ public class ZhiyunAccountBiz {
|
|
|
|
|
if(!content.isEmpty()){
|
|
|
|
|
feignSchool.addSchool(content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void synQuestion(){
|
|
|
|
|
List<SchoolVo> schoolVoList = feignSchool.list();
|
|
|
|
|
schoolVoList.forEach(schoolVo -> {
|
|
|
|
|
String content = zhiYunApi.findAllQuestion();
|
|
|
|
|
String content = zhiYunApi.findAllQuestion(10,1);
|
|
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(content);
|
|
|
|
|
Integer code = jsonObject.getInt("code");
|
|
|
|
|
if(code == 200){
|
|
|
|
|
JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
|
Integer totalPage = data.getInt("totalPages");
|
|
|
|
|
JSONArray contentObj = data.getJSONArray("content");
|
|
|
|
|
dealQuestion(contentObj);
|
|
|
|
|
if(totalPage>1){
|
|
|
|
|
for(int i = 2 ;i<=totalPage;i++){
|
|
|
|
|
dealQuestion(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dealQuestion(int pageIndex){
|
|
|
|
|
String content = zhiYunApi.findAllQuestion(10,pageIndex);
|
|
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(content);
|
|
|
|
|
Integer code = jsonObject.getInt("code");
|
|
|
|
|
if(code == 200){
|
|
|
|
|
JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
|
JSONArray contentObj = data.getJSONArray("content");
|
|
|
|
|
dealQuestion(contentObj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dealQuestion(JSONArray jsonArray){
|
|
|
|
|
if(jsonArray == null) {return;}
|
|
|
|
|
List<QuestionVo> questionVoList = new ArrayList<>();
|
|
|
|
|
jsonArray.forEach(object -> {
|
|
|
|
|
JSONObject qObject = (JSONObject) object;
|
|
|
|
|
Integer id = qObject.getInt("id");
|
|
|
|
|
Integer courseId = qObject.getInt("courseId");
|
|
|
|
|
String name = qObject.getStr("name");
|
|
|
|
|
Integer type = qObject.getInt("questionType");
|
|
|
|
|
String answer = qObject.getStr("answers");
|
|
|
|
|
Long score = qObject.getLong("score");
|
|
|
|
|
String desc = qObject.getStr("description");
|
|
|
|
|
QuestionVo questionVo = feignQuestion.getByOuterId(id);
|
|
|
|
|
if(questionVo == null){
|
|
|
|
|
questionVo = new QuestionVo();
|
|
|
|
|
CourseVO courseVO = feignCourse.getByOuterId(courseId);
|
|
|
|
|
questionVo.setCourseId(courseVO.getId());
|
|
|
|
|
questionVo.setCourseName(courseVO.getName());
|
|
|
|
|
}
|
|
|
|
|
questionVo.setOuterId(id);
|
|
|
|
|
questionVo.setAnalysis(desc);
|
|
|
|
|
questionVo.setStem(name);
|
|
|
|
|
questionVo.setLevelId(0);
|
|
|
|
|
questionVo.setLevelName("通用");
|
|
|
|
|
questionVo.setAnswerId(convertAnswerId(answer));
|
|
|
|
|
questionVo.setScore(score);
|
|
|
|
|
questionVo.setType(0);
|
|
|
|
|
questionVo.setQuestionType(convertQType(type));
|
|
|
|
|
JSONArray results =qObject.getJSONArray("results");
|
|
|
|
|
List<Answer> answerList = new ArrayList<>();
|
|
|
|
|
for(int i = 0;i<results.size();i++){
|
|
|
|
|
JSONObject rs=(JSONObject) results.get(i);
|
|
|
|
|
String title = rs.getStr("name");
|
|
|
|
|
Answer answer1 = new Answer();
|
|
|
|
|
answer1.setTitle(title);
|
|
|
|
|
answer1.setId(i+1);
|
|
|
|
|
answerList.add(answer1);
|
|
|
|
|
}
|
|
|
|
|
questionVo.setAnswerList(answerList);
|
|
|
|
|
questionVoList.add(questionVo);
|
|
|
|
|
});
|
|
|
|
|
feignQuestion.addAll(questionVoList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Integer> convertAnswerId(String answer){
|
|
|
|
|
List<Integer> rs = new ArrayList<>();
|
|
|
|
|
String[] a = answer.split(",");
|
|
|
|
|
List<String> answerList = Arrays.asList(a);
|
|
|
|
|
// answerList.sort(Comparator.comparingInt(m -> m.charAt(0)));
|
|
|
|
|
answerList.forEach(as->{
|
|
|
|
|
Integer id = as.toLowerCase().chars().boxed().findFirst().orElse(0)-96;
|
|
|
|
|
rs.add(id);
|
|
|
|
|
});
|
|
|
|
|
return rs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Integer convertQType(Integer outerType){
|
|
|
|
|
switch (outerType){
|
|
|
|
|
case 1:
|
|
|
|
|
return 1;
|
|
|
|
|
case 2:
|
|
|
|
|
return 2;
|
|
|
|
|
case 3:
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void synAllCourse(){
|
|
|
|
|
String courseStr = zhiYunApi.findAllCource();
|
|
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(courseStr);
|
|
|
|
|
Integer code = jsonObject.getInt("code");
|
|
|
|
|
String imgServerUrl = "http://cloud.sztzjy.com";
|
|
|
|
|
if(code == 200){
|
|
|
|
|
JSONArray couresArray = jsonObject.getJSONArray("data");
|
|
|
|
|
if(couresArray == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<CourseVO> courseVOList = new ArrayList<>();
|
|
|
|
|
couresArray.forEach(object -> {
|
|
|
|
|
JSONObject co = (JSONObject) object;
|
|
|
|
|
Integer id = co.getInt("id");
|
|
|
|
|
String name = co.getStr("name");
|
|
|
|
|
String img = co.getStr("courseImgUrl");
|
|
|
|
|
String coverUrl ="";
|
|
|
|
|
if(!StringUtils.isEmpty(img)&&img.startsWith("/")){
|
|
|
|
|
coverUrl = imgServerUrl+img;
|
|
|
|
|
}
|
|
|
|
|
Integer learnCount = co.getInt("learnersCount");
|
|
|
|
|
String desc = co.getStr("description");
|
|
|
|
|
CourseVO vo = feignCourse.getByOuterId(id);
|
|
|
|
|
if(vo== null){
|
|
|
|
|
vo = new CourseVO();
|
|
|
|
|
}
|
|
|
|
|
vo.setContent(desc);
|
|
|
|
|
vo.setLearningCount(learnCount);
|
|
|
|
|
vo.setName(name);
|
|
|
|
|
vo.setThumbnail(coverUrl);
|
|
|
|
|
vo.setOuterId(id);
|
|
|
|
|
courseVOList.add(vo);
|
|
|
|
|
});
|
|
|
|
|
if(courseVOList.size()>0){
|
|
|
|
|
feignCourse.addAll(courseVOList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void synCourse(Integer schoolId){
|
|
|
|
|
String content = zhiYunApi.findClassesBySchoolId(schoolId);
|
|
|
|
|
//图片baseUrl http://cloud.sztzjy.com/
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|