package com.yizhi.application.research.importer;

import com.yizhi.core.application.file.domain.FileInfo;
import com.yizhi.core.application.file.domain.Template;
import com.yizhi.core.application.file.imp.AbstractImporter;
import com.yizhi.core.application.file.imp.ImportCallBack;

import java.io.InputStream;
import java.util.List;


/**
 * @Author: shengchenglong
 * @Date: 2018/3/17 12:25
 */
public class QuestionImporter extends AbstractImporter {

//    public QuestionImporter(String fileUrl, String fileName, String savePath, ImportCallBack callBack) {
//        super(fileUrl, fileName, savePath, callBack);
//    }
//
//
//
//    @Override
//    public Object parse(FileInfo fileInfo) {
//        try {
//            InputStream inputStream = fileInfo.getContent();
////            InputStream inputStream = new FileInputStream(new File("/Users/shengchenglong/Desktop/aaa.xlsx"));
//
//            List<TrResearchQuestion> questionList = new ArrayList<>();
//
//
//            Workbook wb = WorkbookFactory.create(inputStream);
//            Sheet sheet = wb.getSheetAt(0);
//
//            TrResearchQuestion question = null;
//            for (int i = 0; i <= sheet.getLastRowNum(); i++) {
//                if (i < 2) {
//                    continue;
//                }
//                Row row = sheet.getRow(i);
//                question = new TrResearchQuestion();
//                List<TrResearchQuestionOption> options = new ArrayList<>();
//                for (int j = 0; j < row.getLastCellNum(); j++) {
//                    Cell cell = row.getCell(j);
//
//                    // 问题内容
//                    if (j == 0) {
//                        question.setContent(cell.getStringCellValue());
//                    }
//
//                    // 问题类型
//                    if (j == 1) {
//                        String questionType = cell.getStringCellValue().trim();
//                        if (questionType.equalsIgnoreCase("单选题")) {
//                            question.setType(QuestionType.SINGLE_OPTION_QUESTION.getValue());
//                            question.setOptions(new ArrayList<TrResearchQuestionOption>());
//                        } else if (questionType.equalsIgnoreCase("多选题")) {
//                            question.setType(QuestionType.MULTIPLE_OPTION_QUESTION.getValue());
//                            question.setOptions(new ArrayList<TrResearchQuestionOption>());
//                        } else if (questionType.equalsIgnoreCase("打分题")) {
//                            question.setType(QuestionType.POINT_QUESTION.getValue());
//                            question.setOptions(new ArrayList<TrResearchQuestionOption>());
//                        } else if (questionType.equalsIgnoreCase("问答题")) {
//                            question.setType(QuestionType.ASK_ANSWER_QUESTION.getValue());
//                        }
//                    }
//
//                    // 是否必答
//                    if (j == 2) {
//                        question.setNeedAnswer(cell.getStringCellValue().trim().equals("是") ? 1 : 0);
//                    }
//
//                    // 最多选择
//                    if (j == 3 && question.getType() == QuestionType.MULTIPLE_OPTION_QUESTION.getValue()) {
////                        question.setMaxSelectItem(StringUtils.isEmpty(cell.getStringCellValue()) ? Integer.valueOf(cell.getStringCellValue()) : null);
//                        question.setMaxSelectItem((int) cell.getNumericCellValue());
//                    }
//
//                    // 最少选择
//                    if (j == 4 && question.getType() == QuestionType.MULTIPLE_OPTION_QUESTION.getValue()) {
////                        question.setMinSelectItem(StringUtils.isEmpty(cell.getStringCellValue()) ? Integer.valueOf(cell.getStringCellValue()) : null);
//                        question.setMinSelectItem((int) cell.getNumericCellValue());
//                    }
//
//                    // 组装问题选项
//                    if (j >= 5 && (question.getType() == QuestionType.MULTIPLE_OPTION_QUESTION.getValue()
//                            || question.getType() == QuestionType.SINGLE_OPTION_QUESTION.getValue()
//                            || question.getType() == QuestionType.POINT_QUESTION.getValue()) &&
//                            !StringUtils.isEmpty(cell.getStringCellValue())) {
//                        TrResearchQuestionOption option = new TrResearchQuestionOption();
//                        option.setContent(cell.getStringCellValue());
//                        option.setEditable(0);
//                        options.add(option);
//                        question.setOptions(options);
//                    }
//
//                }
//                questionList.add(question);
//            }
//            return questionList;
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (InvalidFormatException e) {
//            e.printStackTrace();
//        }
//        return null;
//    }

    public QuestionImporter(String fileUrl, String fileName, String savePath, ImportCallBack callBack, Template template, Class domainClazz) {
        super(fileUrl, fileName, savePath, callBack, template, domainClazz);
    }

    @Override
    protected List<String[]> parse(FileInfo fileInfo, Template template) {
        return null;
    }

	@Override
	protected List<String[]> parse(InputStream arg0, Template arg1) {
		// TODO Auto-generated method stub
		return null;
	}
}
