导入word试题,未完
parent
e74658d115
commit
48be5321af
@ -0,0 +1,207 @@
|
||||
package cn.jlw.util.wmf2png;
|
||||
|
||||
import net.arnx.wmf2svg.gdi.svg.SvgGdi;
|
||||
import net.arnx.wmf2svg.gdi.wmf.WmfParser;
|
||||
import org.apache.batik.transcoder.TranscoderException;
|
||||
import org.apache.batik.transcoder.TranscoderInput;
|
||||
import org.apache.batik.transcoder.TranscoderOutput;
|
||||
import org.apache.batik.transcoder.image.ImageTranscoder;
|
||||
import org.apache.batik.transcoder.image.JPEGTranscoder;
|
||||
import org.apache.batik.transcoder.wmf.tosvg.WMFTranscoder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.*;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class WmfToPng {
|
||||
|
||||
enum FileType {
|
||||
SVG,
|
||||
PNG;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String result = convert("d:\\80814378377.wmf");
|
||||
System.out.println(result);
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String convert2(String path) throws TranscoderException,
|
||||
IOException {
|
||||
String wmfPath = path;
|
||||
File wmf = new File(wmfPath);
|
||||
FileInputStream wmfStream = new FileInputStream(wmf);
|
||||
ByteArrayOutputStream imageOut = new ByteArrayOutputStream();
|
||||
int noOfByteRead = 0;
|
||||
while ((noOfByteRead = wmfStream.read()) != -1) {
|
||||
imageOut.write(noOfByteRead);
|
||||
}
|
||||
imageOut.flush();
|
||||
wmfStream.close();
|
||||
// wmf 转换为svg
|
||||
WMFTranscoder transcoder = new WMFTranscoder();
|
||||
// TranscodingHints hints = new TranscodingHints();
|
||||
// hints.put(WMFTranscoder.KEY_HEIGHT, 1000f);
|
||||
// hints.put(WMFTranscoder.KEY_WIDTH, 1500f);
|
||||
// transcoder.setTranscodingHints(hints);
|
||||
TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(
|
||||
imageOut.toByteArray()));
|
||||
ByteArrayOutputStream svg = new ByteArrayOutputStream();
|
||||
TranscoderOutput output = new TranscoderOutput(svg);
|
||||
transcoder.transcode(input, output);
|
||||
String svgFile = StringUtils.replace(wmfPath, "wmf", "svg");
|
||||
FileOutputStream fileOut = new FileOutputStream(svgFile);
|
||||
fileOut.write(svg.toByteArray());
|
||||
fileOut.flush();
|
||||
fileOut.close();
|
||||
svg.close();
|
||||
// svg -> jpg
|
||||
ImageTranscoder it = new JPEGTranscoder();
|
||||
it.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(0.5f));
|
||||
ByteArrayOutputStream jpg = new ByteArrayOutputStream();
|
||||
it.transcode(new TranscoderInput(new ByteArrayInputStream(svg
|
||||
.toByteArray())), new TranscoderOutput(jpg));
|
||||
String jpgFile = StringUtils.replace(wmfPath, "wmf", "jpg");
|
||||
FileOutputStream jpgOut = new FileOutputStream(jpgFile);
|
||||
jpgOut.write(jpg.toByteArray());
|
||||
jpgOut.flush();
|
||||
jpgOut.close();
|
||||
jpg.close();
|
||||
// Filor.deleteFile(svgFile);// 删除掉中间文件
|
||||
return jpgFile;
|
||||
}
|
||||
|
||||
public static String convert(String path, FileType fileType) {
|
||||
try {
|
||||
String svgFile = StringUtils.replace(path, "wmf", "svg");
|
||||
String filePath = StringUtils.replace(path, "wmf", "png");
|
||||
switch (fileType) {
|
||||
case PNG:
|
||||
wmfToSvg(path, svgFile);
|
||||
svgToJpg(svgFile, filePath);
|
||||
break;
|
||||
case SVG:
|
||||
wmfToSvg(path, svgFile);
|
||||
filePath = svgFile;
|
||||
break;
|
||||
}
|
||||
|
||||
return filePath;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
public static String convert(String path) {
|
||||
return convert(path, FileType.PNG);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 将svg转化为JPG
|
||||
*
|
||||
* @param src
|
||||
* @param dest
|
||||
*/
|
||||
public static String svgToJpg(String src, String dest) {
|
||||
FileOutputStream jpgOut = null;
|
||||
FileInputStream svgStream = null;
|
||||
ByteArrayOutputStream svgOut = null;
|
||||
ByteArrayInputStream svgInputStream = null;
|
||||
ByteArrayOutputStream jpg = null;
|
||||
try {
|
||||
// 获取到svg文件
|
||||
File svg = new File(src);
|
||||
svgStream = new FileInputStream(svg);
|
||||
svgOut = new ByteArrayOutputStream();
|
||||
// 获取到svg的stream
|
||||
int noOfByteRead = 0;
|
||||
while ((noOfByteRead = svgStream.read()) != -1) {
|
||||
svgOut.write(noOfByteRead);
|
||||
}
|
||||
JPEGTranscoder it = new JPEGTranscoder();
|
||||
it.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(0.9f));
|
||||
it.addTranscodingHint(ImageTranscoder.KEY_WIDTH, new Float(100));
|
||||
jpg = new ByteArrayOutputStream();
|
||||
svgInputStream = new ByteArrayInputStream(svgOut.toByteArray());
|
||||
it.transcode(new TranscoderInput(svgInputStream),
|
||||
new TranscoderOutput(jpg));
|
||||
jpgOut = new FileOutputStream(dest);
|
||||
jpgOut.write(jpg.toByteArray());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (svgInputStream != null) {
|
||||
svgInputStream.close();
|
||||
}
|
||||
if (jpg != null) {
|
||||
jpg.close();
|
||||
}
|
||||
if (svgStream != null) {
|
||||
svgStream.close();
|
||||
}
|
||||
if (svgOut != null) {
|
||||
svgOut.close();
|
||||
}
|
||||
if (jpgOut != null) {
|
||||
jpgOut.flush();
|
||||
jpgOut.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将wmf转换为svg
|
||||
*
|
||||
* @param src
|
||||
* @param dest
|
||||
*/
|
||||
public static void wmfToSvg(String src, String dest) {
|
||||
boolean compatible = false;
|
||||
try {
|
||||
InputStream in = new FileInputStream(src);
|
||||
WmfParser parser = new WmfParser();
|
||||
final SvgGdi gdi = new SvgGdi(compatible);
|
||||
parser.parse(in, gdi);
|
||||
|
||||
Document doc = gdi.getDocument();
|
||||
OutputStream out = new FileOutputStream(dest);
|
||||
if (dest.endsWith(".svgz")) {
|
||||
out = new GZIPOutputStream(out);
|
||||
}
|
||||
|
||||
output(doc, out);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void output(Document doc, OutputStream out) throws Exception {
|
||||
TransformerFactory factory = TransformerFactory.newInstance();
|
||||
Transformer transformer = factory.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
|
||||
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
|
||||
"-//W3C//DTD SVG 1.0//EN");
|
||||
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd");
|
||||
transformer.transform(new DOMSource(doc), new StreamResult(out));
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.ibeetl.jlw.entity.vo;
|
||||
|
||||
import com.ibeetl.admin.core.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 功能描述: <br>
|
||||
*
|
||||
* @author: mlx
|
||||
* @description:
|
||||
* @date: 2022/12/26 19:53
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SummaryBySigninSettingIdsVO extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 签到配置ID
|
||||
*/
|
||||
private Long teacherOpenCourseStudentSigninSettingId;
|
||||
/**
|
||||
* 签到总人数
|
||||
*/
|
||||
private Float signTotalCount;
|
||||
/**
|
||||
* 签到人数
|
||||
*/
|
||||
private Float signCount;
|
||||
/**
|
||||
* 缺席人数
|
||||
*/
|
||||
private Float signLackCount;
|
||||
/**
|
||||
* 到课率 100最大
|
||||
*/
|
||||
private Float attendRate;
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
package com.ibeetl.jlw.service.strategy;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 策略Context
|
||||
* </p>
|
||||
*
|
||||
* @author mlx
|
||||
* @date 2022/5/30
|
||||
* @modified
|
||||
*/
|
||||
@Component
|
||||
@Lazy
|
||||
@Data
|
||||
@Accessors(chain=true)
|
||||
public class StrategyContext {
|
||||
|
||||
/**
|
||||
* 待处理的文本
|
||||
*/
|
||||
private String text;
|
||||
|
||||
/**
|
||||
* 是否保存处理后的字符串到 {@link #result} 属性中
|
||||
*/
|
||||
private boolean isSaveResult;
|
||||
/**
|
||||
* 策略集合
|
||||
*/
|
||||
@Setter(AccessLevel.PRIVATE)
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private List<WordStrategy> strategyList = Lists.newArrayList();
|
||||
/**
|
||||
* 处理之后的结果集
|
||||
*/
|
||||
@Setter(AccessLevel.PRIVATE)
|
||||
private List<Map<QuestionParagraphTypeEnum, String>> result = Inner.getInstance();
|
||||
|
||||
static class Inner {
|
||||
private static List<Map<QuestionParagraphTypeEnum, String>> result = new ArrayList<>();
|
||||
|
||||
static List<Map<QuestionParagraphTypeEnum, String>> getInstance() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public StrategyContext() {
|
||||
strategyList.add(new WordQuestionOption());
|
||||
strategyList.add(new WordQuestionAnswer());
|
||||
strategyList.add(new WordQuestionStem());
|
||||
strategyList.add(new WordQuestionType());
|
||||
// 必须放在最后一个,用于上述判断完以后,都不成立的话,就认为它是标题。
|
||||
strategyList.add(new WordQuestionOther());
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始处理
|
||||
* @param consumer 每一个段落的消费
|
||||
*/
|
||||
public void start(Consumer<Map<QuestionParagraphTypeEnum, String>> consumer) {
|
||||
|
||||
for (WordStrategy wordStrategy : strategyList) {
|
||||
if (StringUtils.isNotBlank(text) && wordStrategy.support(text)) {
|
||||
// System.out.print("策略:" + wordStrategy.getClass().getSimpleName() + ", 值:\t");
|
||||
/** 得到处理后的值 */
|
||||
String processedResult = wordStrategy.process(text, consumer);
|
||||
if (isSaveResult) {
|
||||
result.add(MapUtil.of(wordStrategy.getTypeEnum(), processedResult));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 题目类型
|
||||
*/
|
||||
@Getter
|
||||
public enum QuestionTypeConcatEnum {
|
||||
|
||||
SINGLE("单选题", 1, "单.+题"),
|
||||
MULTIPLE("多选题",2, "多.+题"),
|
||||
DECIDE("判断题",3, "[判断]{1,2}.+题"),
|
||||
SHORT("简答题",4, "简.+题");
|
||||
|
||||
private String typeName;
|
||||
private Integer typeConcat;
|
||||
/**
|
||||
* 取值正则
|
||||
*/
|
||||
private String regex;
|
||||
|
||||
QuestionTypeConcatEnum(String typeName, Integer typeConcat, String regex) {
|
||||
this.typeName = typeName;
|
||||
this.typeConcat = typeConcat;
|
||||
this.regex = regex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本匹配枚举
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
public static QuestionTypeConcatEnum matchText(@NotNull String text) {
|
||||
for (QuestionTypeConcatEnum typeEnum: QuestionTypeConcatEnum.values()) {
|
||||
if (ReUtil.contains(typeEnum.regex, text)) {
|
||||
return typeEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 段落类型
|
||||
* Integer typeConcat = null;//展示方式(1单选 2多选 3判断 4简答)
|
||||
* int type = 0; // 用于记录当前行内容类型 0标题 1题型 2题干 3选项 4答案
|
||||
*/
|
||||
@Getter
|
||||
public enum QuestionParagraphTypeEnum {
|
||||
|
||||
OTHER(WordQuestionOther.class, 0),
|
||||
TYPE(WordQuestionType.class, 1),
|
||||
STEM(WordQuestionStem.class, 2),
|
||||
OPTION(WordQuestionOption.class, 3),
|
||||
ANSWER(WordQuestionAnswer.class, 4);
|
||||
|
||||
private Class<? extends WordStrategy> clz;
|
||||
private Integer type;
|
||||
|
||||
QuestionParagraphTypeEnum(Class<? extends WordStrategy> clz, Integer type) {
|
||||
this.clz = clz;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.ibeetl.jlw.service.strategy;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 取word的未匹配到的部分
|
||||
* </p>
|
||||
*
|
||||
* @author mlx
|
||||
* @date 2022/5/30
|
||||
* @modified
|
||||
*/
|
||||
public class WordQuestionOther implements WordStrategy<String> {
|
||||
|
||||
private final String REGEX = ".*";
|
||||
|
||||
@Getter
|
||||
private StrategyContext.QuestionParagraphTypeEnum typeEnum = StrategyContext.QuestionParagraphTypeEnum.OTHER;
|
||||
|
||||
|
||||
/**
|
||||
* @param paragraph 段落字符串
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean support(String paragraph) {
|
||||
Matcher matcher = Pattern.compile(REGEX).matcher(paragraph.trim());
|
||||
return matcher.find() && matcher.start() >= 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String process(String paragraph, Consumer<Map<StrategyContext.QuestionParagraphTypeEnum, String>> consumer) {
|
||||
Map<StrategyContext.QuestionParagraphTypeEnum, String> map = new HashMap<>(1);
|
||||
paragraph = paragraph.trim();
|
||||
map.put(typeEnum, paragraph);
|
||||
consumer.accept(map);
|
||||
return paragraph;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue