weiwenhai 6 жил өмнө
parent
commit
cb95a1b7ac
14 өөрчлөгдсөн 690 нэмэгдсэн , 5 устгасан
  1. 59 0
      examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ColumnSetting.java
  2. 48 0
      examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelError.java
  3. 31 0
      examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelProperty.java
  4. 176 0
      examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelReader.java
  5. 9 0
      examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelReaderHandle.java
  6. 73 0
      examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelUtils.java
  7. 195 0
      examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelWriter.java
  8. 37 0
      examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExportUtils.java
  9. 57 0
      examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ImportUtils.java
  10. 1 1
      examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/dto/ObjectiveQuestionStructure.java
  11. 1 1
      examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/dto/SubjectiveQuestionStructure.java
  12. 1 1
      examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/export/ExportPaperAbstractService.java
  13. 1 1
      examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/ExtractConfigFileServiceImpl.java
  14. 1 1
      examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/PropertyServiceImpl.java

+ 59 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ColumnSetting.java

@@ -0,0 +1,59 @@
+package cn.com.qmth.examcloud.core.questions.base.excel;
+
+import cn.com.qmth.examcloud.core.questions.base.excel.ColumnSetting;
+
+public class ColumnSetting implements Comparable<ColumnSetting> {
+
+    private String header;
+    private String fieldName;
+    private int width;
+    private int index;
+
+    public ColumnSetting(String header,String fieldName, int width, int index) {
+        this.header = header;
+        this.fieldName = fieldName;
+        this.width = width;
+        this.index = index;
+    }
+
+    public String getHeader() {
+        return header;
+    }
+
+    public void setHeader(String header) {
+        this.header = header;
+    }
+
+    public int getWidth() {
+        return width;
+    }
+
+    public void setWidth(int width) {
+        this.width = width;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public void setIndex(int index) {
+        this.index = index;
+    }
+
+    public String getFieldName() {
+		return fieldName;
+	}
+
+	public void setFieldName(String fieldName) {
+		this.fieldName = fieldName;
+	}
+
+	@Override
+    public int compareTo(ColumnSetting columnSetting) {
+        if (index < columnSetting.getIndex())
+            return - 1 ;
+        if (index > columnSetting.getIndex())
+            return 1 ;
+        return 0 ;
+    }
+}

+ 48 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelError.java

@@ -0,0 +1,48 @@
+package cn.com.qmth.examcloud.core.questions.base.excel;
+/**
+ * 
+ * @Description: excel导入错误
+ * @author ting.yin
+ * @date 2016年8月19日
+ */
+public class ExcelError {
+
+	/**
+	 * 错误行数
+	 */
+	private int row;
+
+	/**
+	 * 错误类型
+	 */
+	private String excelErrorType;
+
+	public ExcelError() {
+
+	}
+
+	public ExcelError(int row, String excelErrorType) {
+		this.row = row;
+		this.excelErrorType = excelErrorType;
+	}
+	
+	public ExcelError(String excelErrorType) {
+		this.excelErrorType = excelErrorType;
+	}
+	public int getRow() {
+		return row;
+	}
+
+	public void setRow(int row) {
+		this.row = row;
+	}
+
+	public String getExcelErrorType() {
+		return excelErrorType;
+	}
+
+	public void setExcelErrorType(String excelErrorType) {
+		this.excelErrorType = excelErrorType;
+	}
+
+}

+ 31 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelProperty.java

@@ -0,0 +1,31 @@
+package cn.com.qmth.examcloud.core.questions.base.excel;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ExcelProperty {
+	/**
+	 * 导出时列名
+	 */
+    String name() default "";
+    
+	/**
+	 * 导出时列宽
+	 */
+    int width() default 0;
+	/**
+	 * 排序
+	 */
+    int index();
+    /**
+     * 类型
+     * 0:导入(读excel)
+     * 1:导出(写excel)
+     * 2:导入&导出
+     */
+    int type() default 2;
+}

+ 176 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelReader.java

@@ -0,0 +1,176 @@
+package cn.com.qmth.examcloud.core.questions.base.excel;
+
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.DateUtil;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.core.questions.base.excel.ColumnSetting;
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelError;
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelReaderHandle;
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelUtils;
+
+/**
+ * 
+ * @Description: 读取excel
+ * @author ting.yin
+ * @date 2016年8月19日
+ */
+public class ExcelReader extends ExcelUtils {
+
+	private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+	public ExcelReader(Class<?> dataClass) {
+		super(dataClass, true);
+	}
+
+	/**
+	 * 
+	 * @param inputStream
+	 *            输入流
+	 * @param handle
+	 *            单个对象处理器
+	 * @return 错误信息集合
+	 */
+	public List<ExcelError> reader(InputStream inputStream, ExcelReaderHandle handle) {
+		List<ExcelError> excelErrors = new ArrayList<ExcelError>();
+		Workbook wb = null;
+		try {
+			wb = WorkbookFactory.create(inputStream);
+			Sheet sheet = wb.getSheetAt(0);
+			for (int i = 1; i <= sheet.getLastRowNum(); i++) {
+				Row row = sheet.getRow(i);
+				if (row == null) {
+					return excelErrors;
+				}
+				Object dto = getDataClass().newInstance();
+				for (int j = 0; j < this.getColumnSettings().size(); j++) {
+					ColumnSetting columnSetting = this.getColumnSettings().get(j);
+					Cell cell = row.getCell(columnSetting.getIndex());
+					Field field = getDataClass().getDeclaredField(columnSetting.getFieldName());
+					Object obj = convert(cell, field);
+					field.setAccessible(true);
+					field.set(dto, obj);
+				}
+				ExcelError error = handle.handle(dto);
+				if (error != null) {
+					error.setRow(i + 1);
+					excelErrors.add(error);
+				}
+			}
+		} catch (StatusException e) {
+			throw e;
+		} catch (Exception e) {
+			throw new StatusException("580", "EXCEL导入失败", e);
+		} finally {
+			IOUtils.closeQuietly(wb);
+			IOUtils.closeQuietly(inputStream);
+		}
+		return excelErrors;
+	}
+
+	@SuppressWarnings("deprecation")
+	private Object convert(Cell cell, Field field) {
+		if (cell != null) {
+			switch (cell.getCellType()) {
+				case Cell.CELL_TYPE_STRING :
+					return cell.getStringCellValue().toString();
+				case Cell.CELL_TYPE_BOOLEAN :
+					return String.valueOf(cell.getBooleanCellValue());
+				case Cell.CELL_TYPE_NUMERIC :
+					return processNumeric(cell, field);
+			}
+		}
+
+		return null;
+	}
+
+	private Object processNumeric(Cell cell, Field field) {
+
+		if (DateUtil.isCellDateFormatted(cell)) {
+
+			if (field.getType().isAssignableFrom(Date.class)) {
+				return cell.getDateCellValue();
+			} else {
+				return dateFormat.format(cell.getDateCellValue());
+			}
+
+		} else {
+
+			if (field.getType().isAssignableFrom(Integer.class)) {
+
+				return (int) cell.getNumericCellValue();
+
+			} else if (field.getType().isPrimitive() && field.getType().getName().equals("int")) {
+
+				return (int) cell.getNumericCellValue();
+
+			} else if (field.getType().isAssignableFrom(Long.class)) {
+
+				return (long) cell.getNumericCellValue();
+
+			} else if (field.getType().isPrimitive() && field.getType().getName().equals("long")) {
+
+				return (long) cell.getNumericCellValue();
+
+			} else if (field.getType().isAssignableFrom(Short.class)) {
+
+				return (short) cell.getNumericCellValue();
+
+			} else if (field.getType().isPrimitive() && field.getType().getName().equals("short")) {
+
+				return (short) cell.getNumericCellValue();
+
+			} else if (field.getType().isAssignableFrom(Float.class)) {
+
+				return (float) cell.getNumericCellValue();
+
+			} else if (field.getType().isPrimitive() && field.getType().getName().equals("float")) {
+
+				return (float) cell.getNumericCellValue();
+
+			} else if (field.getType().isAssignableFrom(Byte.class)) {
+
+				return (byte) cell.getNumericCellValue();
+
+			} else if (field.getType().isPrimitive() && field.getType().getName().equals("byte")) {
+
+				return (byte) cell.getNumericCellValue();
+
+			} else if (field.getType().isAssignableFrom(Double.class)) {
+
+				return cell.getNumericCellValue();
+
+			} else if (field.getType().isPrimitive()
+					&& field.getType().getName().equals("double")) {
+
+				return cell.getNumericCellValue();
+
+			} else if (field.getType().isAssignableFrom(String.class)) {
+
+				String numStr = String.valueOf(cell.getNumericCellValue());
+				if (numStr.contains("E")) {
+					numStr = new BigDecimal(numStr.trim()).toPlainString();
+				}
+				if (numStr.endsWith(".0"))
+					numStr = numStr.substring(0, numStr.indexOf(".0"));
+				return numStr;
+			} else {
+				return cell.getNumericCellValue();
+			}
+		}
+	}
+}

+ 9 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelReaderHandle.java

@@ -0,0 +1,9 @@
+package cn.com.qmth.examcloud.core.questions.base.excel;
+
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelError;
+
+public interface ExcelReaderHandle {
+	
+	ExcelError handle(Object dto);
+
+}

+ 73 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelUtils.java

@@ -0,0 +1,73 @@
+package cn.com.qmth.examcloud.core.questions.base.excel;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import cn.com.qmth.examcloud.core.questions.base.excel.ColumnSetting;
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelProperty;
+
+/**
+ * Created by zhengmin on 2016/8/17.
+ */
+@SuppressWarnings("rawtypes")
+public abstract class ExcelUtils {
+
+	private Class dataClass;
+    private List<ColumnSetting> columnSettings;
+    
+    public ExcelUtils(Class<?> dataClass , boolean isRead){
+        this.dataClass = dataClass;
+        this.columnSettings = getColumnSettings(dataClass,isRead);
+    }
+
+    public Class getDataClass() {
+        return dataClass;
+    }
+
+    public void setDataClass(Class dataClass) {
+        this.dataClass = dataClass;
+    }
+
+    public List<ColumnSetting> getColumnSettings() {
+        return columnSettings;
+    }
+
+    public void setColumnSettings(List<ColumnSetting> columnSettings) {
+        this.columnSettings = columnSettings;
+    }
+
+    /**
+     * 提取ExcelProperty注解类的字段信息
+     * @param dataClass 需要解析excel的数据类型
+     * @return
+     */
+    protected List<ColumnSetting> getColumnSettings(Class<?> dataClass, boolean isRead){
+		List<ColumnSetting> columnSettings = new ArrayList<>();
+		Field[] fileds = dataClass.getDeclaredFields();
+		for (Field field : fileds) {
+			ExcelProperty exportProperty = field.getAnnotation(ExcelProperty.class);
+			if (exportProperty != null) {
+				if (isRead) {
+					if (exportProperty.type() == 0 || exportProperty.type() == 2) {
+						ColumnSetting columnSetting = new ColumnSetting(
+								exportProperty.name(),field.getName(),exportProperty.width(),
+								exportProperty.index());
+						columnSettings.add(columnSetting);
+					}
+				}else{
+					if (exportProperty.type() == 1 || exportProperty.type() == 2) {
+						ColumnSetting columnSetting = new ColumnSetting(
+								exportProperty.name(), field.getName(),exportProperty.width(),
+								exportProperty.index());
+						columnSettings.add(columnSetting);
+					}
+				}
+			}
+		}
+		Collections.sort(columnSettings);
+		return columnSettings;
+    }
+    
+}

+ 195 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExcelWriter.java

@@ -0,0 +1,195 @@
+package cn.com.qmth.examcloud.core.questions.base.excel;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.poi.xssf.usermodel.*;
+
+import cn.com.qmth.examcloud.core.questions.base.excel.ColumnSetting;
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelUtils;
+
+/**
+ * Created by dizhi on 2016/6/19.
+ */
+public class ExcelWriter extends ExcelUtils {
+
+
+    public ExcelWriter(Class<?> dataClass) {
+        super(dataClass, false);
+    }
+
+    /**
+     * 写入excel
+     *
+     * @param sheetName sheet名称
+     * @param dataset   数据集合
+     * @param out       输出流
+     */
+    @SuppressWarnings("resource")
+	public void write(String sheetName, Collection<?> dataset, OutputStream out) {
+        // 声明一个工作薄
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        // 生成一个表格
+        XSSFSheet sheet = workbook.createSheet(sheetName);
+
+        // 设置表格默认列宽度为15个字节
+        sheet.setDefaultColumnWidth((short) 15);
+        // 生成一个样式
+        XSSFCellStyle style = workbook.createCellStyle();
+        // 设置这些样式
+//        style.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
+//        style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
+//        style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
+//        style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
+//        style.setBorderRight(XSSFCellStyle.BORDER_THIN);
+//        style.setBorderTop(XSSFCellStyle.BORDER_THIN);
+//        style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
+        // 生成一个字体
+//        XSSFFont font = workbook.createFont();
+//        font.setColor(HSSFColor.VIOLET.index);
+//        font.setFontHeightInPoints((short) 12);
+//        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
+//        // 把字体应用到当前的样式
+//        style.setFont(font);
+//        // 生成并设置另一个样式
+//        XSSFCellStyle style2 = workbook.createCellStyle();
+//        style2.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
+//        style2.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
+//        style2.setBorderBottom(XSSFCellStyle.BORDER_THIN);
+//        style2.setBorderLeft(XSSFCellStyle.BORDER_THIN);
+//        style2.setBorderRight(XSSFCellStyle.BORDER_THIN);
+//        style2.setBorderTop(XSSFCellStyle.BORDER_THIN);
+//        style2.setAlignment(XSSFCellStyle.ALIGN_CENTER);
+//        style2.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
+//        // 生成另一个字体
+//        XSSFFont font2 = workbook.createFont();
+//        font2.setBoldweight(XSSFFont.BOLDWEIGHT_NORMAL);
+        // 把字体应用到当前的样式
+        //style2.setFont(font2);
+
+        // 声明一个画图的顶级管理器
+        //HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
+        // 定义注释的大小和位置,详见文档
+//        XSSFComment comment = patriarch.createComment(new HSSFClientAnchor(0,
+//                0, 0, 0, (short) 4, 2, (short) 6, 5));
+//        // 设置注释内容
+//        comment.setString(new HSSFRichTextString("可以在POI中添加注释!"));
+//        // 设置注释作者,当鼠标移动到单元格上是可以在状态栏中看到该内容.
+//        comment.setAuthor("leno");
+
+        List<ColumnSetting> columnSettings = this.getColumnSettings();
+
+        // 产生表格标题行
+        XSSFRow row = sheet.createRow(0);
+        for (short i = 0; i < columnSettings.size(); i++) {
+            XSSFCell cell = row.createCell(i);
+            cell.setCellStyle(style);
+            XSSFRichTextString text = new XSSFRichTextString(columnSettings.get(i).getHeader());
+            cell.setCellValue(text);
+            if (columnSettings.get(i).getWidth() > 0) {
+                sheet.setColumnWidth(i, columnSettings.get(i).getWidth() * 256);
+            }
+        }
+
+        // 遍历集合数据,产生数据行
+        //Iterator<?> it = dataset.iterator();
+        int index = 0;
+        for (Object obj : dataset) {
+            index++;
+            row = sheet.createRow(index);
+            //T t = (T) it.next();
+            // 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
+            for (short i = 0; i < columnSettings.size(); i++) {
+                XSSFCell cell = row.createCell(i);
+                //cell.setCellStyle(style2);
+                String fieldName = columnSettings.get(i).getFieldName();
+
+                try {
+                    Field field = this.getDataClass().getDeclaredField(fieldName);
+                    field.setAccessible(true);
+                    Object value = field.get(obj);
+                    // 判断值的类型后进行强制类型转换
+                    String textValue = null;
+                    // if (value instanceof Integer) {
+                    // int intValue = (Integer) value;
+                    // cell.setCellValue(intValue);
+                    // } else if (value instanceof Float) {
+                    // float fValue = (Float) value;
+                    // textValue = new HSSFRichTextString(
+                    // String.valueOf(fValue));
+                    // cell.setCellValue(textValue);
+                    // } else if (value instanceof Double) {
+                    // double dValue = (Double) value;
+                    // textValue = new HSSFRichTextString(
+                    // String.valueOf(dValue));
+                    // cell.setCellValue(textValue);
+                    // } else if (value instanceof Long) {
+                    // long longValue = (Long) value;
+                    // cell.setCellValue(longValue);
+                    // }
+                    if (value == null) {
+                        textValue = "";
+                    } else if (value instanceof Boolean) {
+                        boolean bValue = (Boolean) value;
+                        textValue = "是";
+                        if (!bValue) {
+                            textValue = "否";
+                        }
+                    } else if (value instanceof Date) {
+                        Date date = (Date) value;
+                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                        textValue = sdf.format(date);
+                    } else {
+                        // 其它数据类型都当作字符串简单处理
+                        textValue = String.valueOf(value);
+                    }
+                    // 如果不是图片数据,就利用正则表达式判断textValue是否全部由数字组成
+                    if (textValue != null) {
+                        Pattern p = Pattern.compile("^//d+(//.//d+)?$");
+                        Matcher matcher = p.matcher(textValue);
+                        if (matcher.matches()) {
+                            // 是数字当作double处理
+                            cell.setCellValue(Double.parseDouble(textValue));
+                        } else {
+                            XSSFRichTextString richString = new XSSFRichTextString(
+                                    textValue);
+
+                            cell.setCellValue(richString);
+                        }
+                    } else {
+                        textValue = "";
+                    }
+                } catch (NoSuchFieldException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                } catch (IllegalAccessException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                } catch (SecurityException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                } catch (IllegalArgumentException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                } finally {
+                    // 清理资源
+                }
+            }
+
+        }
+        try {
+            workbook.write(out);
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+    }
+}

+ 37 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ExportUtils.java

@@ -0,0 +1,37 @@
+package cn.com.qmth.examcloud.core.questions.base.excel;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelWriter;
+
+import java.net.URLEncoder;
+import java.util.Collection;
+
+
+/*
+ * excel导出工具
+ */
+public class ExportUtils {
+
+    private static final String DEFALUT_CONTENT_TYPE = "application/vnd.ms-excel";
+
+    private static final String DEFALUT_EXT = ".xlsx";
+
+    public static void exportEXCEL(String fileName,Class<?> dataClass,
+                             Collection<?> dataset,HttpServletResponse response) {
+        try {
+        	
+            response.setHeader("Content-Disposition", "inline; filename="
+                    +URLEncoder.encode(fileName, "UTF-8") + DEFALUT_EXT);
+            response.setContentType(DEFALUT_CONTENT_TYPE);
+            ServletOutputStream outputStream = response.getOutputStream();
+            ExcelWriter excelExporter = new ExcelWriter(dataClass);
+            excelExporter.write("sheet1",dataset,outputStream);
+            outputStream.flush();
+            outputStream.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 57 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/excel/ImportUtils.java

@@ -0,0 +1,57 @@
+package cn.com.qmth.examcloud.core.questions.base.excel;
+
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+/**
+ * Created by songyue on 17/7/14.
+ */
+public final class ImportUtils {
+
+    protected static final Logger logger = LoggerFactory.getLogger(ImportUtils.class);
+
+    public static final String TEMP_FILE_IMP = "fileImport/";
+
+    public static final String TEMP_FILE_EXP = "fileExport/";
+
+    static {
+        init();
+    }
+
+    /**
+     * 初始化文件夹
+     */
+    public static void init() {
+        File temp_file_exp = new File(TEMP_FILE_EXP);
+        File temp_file_imp = new File(TEMP_FILE_IMP);
+        // 如果输出目标文件夹不存在,则创建
+        if (!temp_file_imp.exists()) {
+            temp_file_imp.mkdirs();
+        }
+        if (!temp_file_exp.exists()) {
+            temp_file_exp.mkdirs();
+        }
+    }
+
+    /**
+     * 获取上传文件
+     *
+     * @param file
+     * @return
+     */
+    public static File getUploadFile(MultipartFile file) throws Exception {
+        String fileName = file.getOriginalFilename();
+        File tempFile = new File(TEMP_FILE_IMP + fileName);
+        OutputStream os = new FileOutputStream(tempFile);
+        IOUtils.copyLarge(file.getInputStream(), os);
+        IOUtils.closeQuietly(os);
+        return tempFile;
+    }
+
+}

+ 1 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/dto/ObjectiveQuestionStructure.java

@@ -5,8 +5,8 @@ import java.io.Serializable;
 import org.apache.commons.lang3.StringUtils;
 
 import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelProperty;
 import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelProperty;
 
 /**
  * @author  	chenken

+ 1 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/dto/SubjectiveQuestionStructure.java

@@ -2,7 +2,7 @@ package cn.com.qmth.examcloud.core.questions.service.bean.dto;
 
 import java.io.Serializable;
 
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelProperty;
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelProperty;
 
 /**
  * @author  	chenken

+ 1 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/export/ExportPaperAbstractService.java

@@ -42,7 +42,6 @@ import org.springframework.data.domain.Example;
 
 import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelWriter;
 
 import com.google.gson.Gson;
 
@@ -81,6 +80,7 @@ import cn.com.qmth.examcloud.core.questions.service.QuestionAudioService;
 import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
 import cn.com.qmth.examcloud.core.questions.base.FileDisposeUtil;
 import cn.com.qmth.examcloud.core.questions.base.enums.ExamFileType;
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelWriter;
 import cn.com.qmth.examcloud.core.questions.base.word.DocxProcessUtil;
 import freemarker.template.Configuration;
 import freemarker.template.Template;

+ 1 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/ExtractConfigFileServiceImpl.java

@@ -1,7 +1,6 @@
 package cn.com.qmth.examcloud.core.questions.service.impl;
 
 import cn.com.qmth.examcloud.core.questions.base.core.ExamCourseDto;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelWriter;
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
 import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
 import cn.com.qmth.examcloud.core.questions.base.FileDisposeUtil;
@@ -10,6 +9,7 @@ import cn.com.qmth.examcloud.core.questions.base.SpringContextUtils;
 import cn.com.qmth.examcloud.core.questions.base.enums.ExamFileType;
 import cn.com.qmth.examcloud.core.questions.base.enums.ExportType;
 import cn.com.qmth.examcloud.core.questions.base.enums.ExportWay;
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelWriter;
 import cn.com.qmth.examcloud.core.questions.base.word.DocxProcessUtil;
 import cn.com.qmth.examcloud.core.questions.dao.ExportServiceManageRepo;
 import cn.com.qmth.examcloud.core.questions.dao.ExtractConfigRepo;

+ 1 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/PropertyServiceImpl.java

@@ -7,8 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
 import cn.com.qmth.examcloud.core.questions.service.bean.PropertyAssembler;
+import cn.com.qmth.examcloud.core.questions.base.excel.ExcelError;
 import cn.com.qmth.examcloud.core.questions.dao.PropertyRepo;
 import cn.com.qmth.examcloud.core.questions.dao.entity.dto.PropertyDto;
 import cn.com.qmth.examcloud.core.questions.dao.entity.Property;