Kaynağa Gözat

docs: 删除文件

ChenSiTong 6 yıl önce
ebeveyn
işleme
f26fd21489

+ 0 - 166
src/main/java/nju/seec/helper/util/BokUtil.java

@@ -1,166 +0,0 @@
-package nju.seec.helper.util;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
-import nju.seec.helper.dto.question.BaseQuestionDTO;
-import nju.seec.helper.dto.question.ChoiceQuestionDTO;
-import nju.seec.helper.dto.question.TrueOrFalseQuestionDTO;
-import nju.seec.helper.enums.ExceptionType;
-import nju.seec.helper.enums.QuestionType;
-import nju.seec.helper.exception.HelperException;
-import nju.seec.helper.vo.question.BokQuestion;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageImpl;
-import org.springframework.data.domain.Pageable;
-import org.springframework.stereotype.Component;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.stream.Collectors;
-
-/**
- * @author xst
- * <p>
- * updated by cst
- */
-@Slf4j
-@Component
-public class BokUtil {
-    private final RestRequestUtil restRequestUtil;
-    private final GuavaCacheUtil cacheUtils;
-    @Value("${bok.tqUrl}")
-    private String tqUrl;
-    @Value("${bok.tqStemSearchUrl}")
-    private String tqStemSearchUrl;
-    @Value("${bok.tqIdSearchUrl}")
-    private String tqIdSearchUrl;
-
-    public BokUtil(RestRequestUtil restRequestUtil, GuavaCacheUtil cacheUtils) {
-        this.restRequestUtil = restRequestUtil;
-        this.cacheUtils = cacheUtils;
-    }
-
-    public Page<BokQuestion> bokFindByStemLike(String stem, Pageable pageable) {
-        Map<String, String> urlParams = ImmutableMap.of(
-                "content", stem,
-                "page", String.valueOf(1 + pageable.getPageNumber()),
-                "size", String.valueOf(pageable.getPageSize())
-        );
-        BokSearchResult result = restRequestUtil.sendGetRequest(tqStemSearchUrl, BokSearchResult.class, urlParams);
-
-        List<BokQuestion> bokQuestions = result.getEmbedded().getQuestions();
-        cacheUtils.setAll(BOK_CACHE_NAME, bokQuestions.parallelStream().collect(Collectors.toMap(BokQuestion::getId, bokQuestion -> bokQuestion)));
-        return new PageImpl<>(bokQuestions, pageable, result.getPage().getTotalElements());
-    }
-
-    private static String BOK_CACHE_NAME = "BOK";
-
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    public List<BokQuestion> bokFindByIdIn(final List<String> ids) {
-        Map<String, BokQuestion> bokQuestionsMap = Maps.newHashMapWithExpectedSize(ids.size());
-
-        final Map<String, BokQuestion> cacheBokQuestionsMap = (Map) cacheUtils.multiGet(BOK_CACHE_NAME, ids);
-        bokQuestionsMap.putAll(cacheBokQuestionsMap);
-
-        List<String> requestIds = Lists.newArrayList(ids);
-        requestIds.removeAll(cacheBokQuestionsMap.keySet());
-        //未缓存的去这里拿
-        if (!requestIds.isEmpty()) {
-            Map<String, String> urlParams = ImmutableMap.of("id", requestIds.stream().reduce((a, b) -> a + "," + b).orElse(""));
-
-            BokSearchResult result = restRequestUtil.sendGetRequest(tqIdSearchUrl, BokSearchResult.class, urlParams);
-            List<BokQuestion> bokQuestions = result.getEmbedded().getQuestions();
-
-            Map<String, BokQuestion> remoteBokQuestionsMap = bokQuestions.parallelStream().collect(Collectors.toMap(BokQuestion::getId, bokQuestion -> bokQuestion));
-
-            bokQuestionsMap.putAll(remoteBokQuestionsMap);
-            cacheUtils.setAll(BOK_CACHE_NAME, (Map) remoteBokQuestionsMap);
-        }
-
-        return ids.stream()
-                .map(bokQuestionsMap::get)
-                .collect(Collectors.toList());
-    }
-
-    public BokQuestion bokFindById(String questionId) {
-        Object cachedBokQuestion = cacheUtils.get(BOK_CACHE_NAME, questionId);
-        if (cachedBokQuestion instanceof BokQuestion) {
-            return (BokQuestion) cachedBokQuestion;
-        }
-        BokQuestion bokQuestion = restRequestUtil.sendGetRequest(tqUrl + "/" + questionId, BokQuestion.class, Collections.emptyMap());
-        cacheUtils.set(BOK_CACHE_NAME, bokQuestion.getId(), bokQuestion);
-        return bokQuestion;
-    }
-
-    public BokQuestion createQuestion(String questionId, BaseQuestionDTO baseQuestionDTO) {
-        BokQuestion bokQuestion = getQuestion(baseQuestionDTO);
-        bokQuestion.setId(questionId);
-        bokQuestion = restRequestUtil.sendPostRequest(tqUrl, bokQuestion, BokQuestion.class);
-        return bokQuestion;
-    }
-
-    public BokQuestion modifyQuestion(String questionId, BaseQuestionDTO baseQuestionDTO) {
-        BokQuestion bokQuestion = getQuestion(baseQuestionDTO);
-        bokQuestion.setId(questionId);
-        restRequestUtil.sendPutRequest(tqUrl + "/" + questionId, bokQuestion);
-        return bokFindById(questionId);
-    }
-
-    public void deleteQuestion(String questionId) {
-        restRequestUtil.sendDeleteRequest(tqUrl + "/" + questionId);
-    }
-
-    private BokQuestion getQuestion(BaseQuestionDTO baseQuestionDTO) {
-        BokQuestion bokQuestion = new BokQuestion();
-        bokQuestion.setType(baseQuestionDTO.getType());
-        bokQuestion.setStem(baseQuestionDTO.getStem());
-        bokQuestion.setKeyPoints(baseQuestionDTO.getKeyPoints());
-        bokQuestion.setTags(baseQuestionDTO.getTags());
-        bokQuestion.setKnowledgeId(baseQuestionDTO.getKnowledgeId());
-
-        final QuestionType questionType = QuestionType.getQuestionType(baseQuestionDTO.getType());
-        switch (Objects.requireNonNull(questionType)) {
-            case CHOICE:
-                ChoiceQuestionDTO choiceQuestionDTO = (ChoiceQuestionDTO) baseQuestionDTO;
-                bokQuestion.setOptions(choiceQuestionDTO.getOptions());
-                bokQuestion.setAnswer(choiceQuestionDTO.getAnswer());
-                bokQuestion.setAnalysis(choiceQuestionDTO.getAnalysis());
-                break;
-            case TRUE_FALSE:
-                TrueOrFalseQuestionDTO trueOrFalseQuestionDTO = (TrueOrFalseQuestionDTO) baseQuestionDTO;
-                bokQuestion.setAnswer(String.valueOf(trueOrFalseQuestionDTO.getAnswer()));
-                bokQuestion.setAnalysis(trueOrFalseQuestionDTO.getAnalysis());
-                break;
-            default:
-                throw HelperException.of(ExceptionType.ERROR, "不支持的题目类型");
-        }
-        return bokQuestion;
-    }
-
-    @Data
-    private static class BokSearchResult {
-        @JsonProperty("_embedded")
-        private Embedded embedded = new Embedded();
-        private Page page;
-
-        @Data
-        private static class Embedded {
-            private List<BokQuestion> questions = Collections.emptyList();
-        }
-
-        @Data
-        private static class Page {
-            private int size;
-            private int number;
-            private int totalPages;
-            private long totalElements;
-        }
-    }
-}

+ 0 - 59
src/main/java/nju/seec/helper/util/file/FileParserContext.java

@@ -1,59 +0,0 @@
-package nju.seec.helper.util.file;
-
-import com.google.common.collect.ImmutableMap;
-import lombok.SneakyThrows;
-import lombok.experimental.UtilityClass;
-import nju.seec.helper.enums.ExceptionType;
-import nju.seec.helper.exception.HelperException;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
-import org.apache.poi.xslf.usermodel.XMLSlideShow;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * @author cst
- */
-@UtilityClass
-public class FileParserContext {
-    private static final Map<String, FileParser> FILE_PARSER_MAP;
-
-    static {
-        FILE_PARSER_MAP = ImmutableMap.of(
-                "application/pdf", file -> {
-                    PDDocument pdf = PDDocument.load(file.getInputStream());
-                    return FileInfo.of(pdf.getNumberOfPages(), "pdf");
-                }
-                , "application/vnd.ms-powerpoint", file -> {
-                    HSLFSlideShow ppt = new HSLFSlideShow(file.getInputStream());
-                    return FileInfo.of(ppt.getSlides().size(), "ppt");
-                }
-                , "application/vnd.openxmlformats-officedocument.presentationml.presentation", file -> {
-                    XMLSlideShow pptx = new XMLSlideShow(file.getInputStream());
-                    return FileInfo.of(pptx.getSlides().size(), "pptx");
-                }
-        );
-    }
-
-    @SneakyThrows
-    public FileInfo getFileInfo(MultipartFile file) {
-        return Optional.ofNullable(FILE_PARSER_MAP.get(file.getContentType()))
-                .orElseThrow(() -> HelperException.of(ExceptionType.FORBIDDEN, "不支持的文件类型"))
-                .parse(file);
-    }
-
-    @FunctionalInterface
-    private interface FileParser {
-        /**
-         * 解析文件信息
-         *
-         * @param file
-         * @return
-         * @throws IOException
-         */
-        FileInfo parse(MultipartFile file) throws IOException;
-    }
-}