|
|
|
@ -9,7 +9,6 @@ import cn.jlw.validate.ValidateConfig;
|
|
|
|
|
import com.ibeetl.admin.core.annotation.Function;
|
|
|
|
|
import com.ibeetl.admin.core.entity.CoreUser;
|
|
|
|
|
import com.ibeetl.admin.core.file.FileService;
|
|
|
|
|
import com.ibeetl.admin.core.util.PlatformException;
|
|
|
|
|
import com.ibeetl.admin.core.util.TimeTool;
|
|
|
|
|
import com.ibeetl.admin.core.web.JsonResult;
|
|
|
|
|
import com.ibeetl.jlw.entity.CourseInfo;
|
|
|
|
@ -29,9 +28,6 @@ import com.ibeetl.jlw.web.query.ResourcesQuestionQuery;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Name;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
|
@ -57,10 +53,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static cn.hutool.core.util.ArrayUtil.join;
|
|
|
|
|
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
|
|
|
|
|
import static cn.jlw.util.excel.ExcelUtil.standardName;
|
|
|
|
|
import static com.ibeetl.admin.core.util.StreamUtils.listJoin;
|
|
|
|
|
import static com.ibeetl.admin.core.util.excelGroupValidation.ExcelUtil.replaceNameName;
|
|
|
|
|
import static java.util.stream.Collectors.toList;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ResourcesQuestion 接口
|
|
|
|
@ -439,49 +432,49 @@ public class ResourcesQuestionController{
|
|
|
|
|
|
|
|
|
|
workbook = new XSSFWorkbook(is);
|
|
|
|
|
|
|
|
|
|
// 获取模板中的Sheet1
|
|
|
|
|
Sheet sheetPro = workbook.getSheet("Sheet1");
|
|
|
|
|
//// 获取模板中的Sheet1
|
|
|
|
|
//Sheet sheetPro = workbook.getSheet("Sheet1");
|
|
|
|
|
|
|
|
|
|
// 查询特定的课程名称及其章的名称
|
|
|
|
|
List<String> courseInfoArr = new ArrayList<String>();
|
|
|
|
|
Map<String, List<String>> map = new HashMap<String, List<String>>();
|
|
|
|
|
|
|
|
|
|
CourseInfoQuery courseInfoQuery = new CourseInfoQuery();
|
|
|
|
|
courseInfoQuery.setCourseLabelStatus(1);
|
|
|
|
|
// courseInfoQuery.setCourseLabelTypes("应用课程类");
|
|
|
|
|
courseInfoQuery.setCourseInfoType(1);
|
|
|
|
|
courseInfoQuery.setCourseInfoStatus(1);
|
|
|
|
|
|
|
|
|
|
List<CourseInfo> courseInfoList = courseInfoService.getCourseInfoValues(courseInfoQuery);
|
|
|
|
|
|
|
|
|
|
if(null != courseInfoList && courseInfoList.size()>0){
|
|
|
|
|
for(int i=0;i<courseInfoList.size();i++){
|
|
|
|
|
String mergeCourseNameId = courseInfoList.get(i).getCourseInfoName() + "__ID" + courseInfoList.get(i).getCourseInfoId();
|
|
|
|
|
mergeCourseNameId = standardName(mergeCourseNameId);
|
|
|
|
|
// key不可重复
|
|
|
|
|
mergeCourseNameId = replaceNameName(mergeCourseNameId);
|
|
|
|
|
courseInfoArr.add(mergeCourseNameId);
|
|
|
|
|
|
|
|
|
|
// 整理数据,放入一个Map中,mapkey存放父地点,value 存放院校下的班级
|
|
|
|
|
Object chapter = courseInfoList.get(i).get("chapter");
|
|
|
|
|
if(null != chapter && StringUtils.isNotBlank(chapter.toString())){
|
|
|
|
|
map.put(mergeCourseNameId, Arrays.stream(chapter.toString().split(",")).map(String::trim).collect(toList()));
|
|
|
|
|
}else {
|
|
|
|
|
map.put(mergeCourseNameId,new ArrayList<>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
throw new PlatformException("请先添加院校");
|
|
|
|
|
}
|
|
|
|
|
// CourseInfoQuery courseInfoQuery = new CourseInfoQuery();
|
|
|
|
|
// courseInfoQuery.setCourseLabelStatus(1);
|
|
|
|
|
//// courseInfoQuery.setCourseLabelTypes("应用课程类");
|
|
|
|
|
// courseInfoQuery.setCourseInfoType(1);
|
|
|
|
|
// courseInfoQuery.setCourseInfoStatus(1);
|
|
|
|
|
|
|
|
|
|
//List<CourseInfo> courseInfoList = courseInfoService.getCourseInfoValues(courseInfoQuery);
|
|
|
|
|
//
|
|
|
|
|
//if(null != courseInfoList && courseInfoList.size()>0){
|
|
|
|
|
// for(int i=0;i<courseInfoList.size();i++){
|
|
|
|
|
// String mergeCourseNameId = courseInfoList.get(i).getCourseInfoName() + "__ID" + courseInfoList.get(i).getCourseInfoId();
|
|
|
|
|
// mergeCourseNameId = standardName(mergeCourseNameId);
|
|
|
|
|
// // key不可重复
|
|
|
|
|
// mergeCourseNameId = replaceNameName(mergeCourseNameId);
|
|
|
|
|
// courseInfoArr.add(mergeCourseNameId);
|
|
|
|
|
//
|
|
|
|
|
// // 整理数据,放入一个Map中,mapkey存放父地点,value 存放院校下的班级
|
|
|
|
|
// Object chapter = courseInfoList.get(i).get("chapter");
|
|
|
|
|
// if(null != chapter && StringUtils.isNotBlank(chapter.toString())){
|
|
|
|
|
// map.put(mergeCourseNameId, Arrays.stream(chapter.toString().split(",")).map(String::trim).collect(toList()));
|
|
|
|
|
// }else {
|
|
|
|
|
// map.put(mergeCourseNameId,new ArrayList<>());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//}else {
|
|
|
|
|
// throw new PlatformException("请先添加院校");
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// 创建一个专门用来存放地区信息的隐藏sheet页
|
|
|
|
|
// 因此也不能在现实页之前创建,否则无法隐藏。
|
|
|
|
|
Sheet hideSheet = workbook.createSheet("课程章节信息");
|
|
|
|
|
// 将此sheet隐藏
|
|
|
|
|
workbook.setSheetHidden(workbook.getSheetIndex(hideSheet), true);
|
|
|
|
|
//Sheet hideSheet = workbook.createSheet("课程章节信息");
|
|
|
|
|
//// 将此sheet隐藏
|
|
|
|
|
//workbook.setSheetHidden(workbook.getSheetIndex(hideSheet), true);
|
|
|
|
|
|
|
|
|
|
int rowId = 0;
|
|
|
|
|
//int rowId = 0;
|
|
|
|
|
// 设置第一行,存省的信息
|
|
|
|
|
// Row provinceRow = hideSheet.createRow(rowId++);
|
|
|
|
|
// provinceRow.createCell(0).setCellValue("省列表");
|
|
|
|
@ -490,23 +483,23 @@ public class ResourcesQuestionController{
|
|
|
|
|
// provinceCell.setCellValue(provinceArr.get(i));
|
|
|
|
|
// }
|
|
|
|
|
// 将具体的数据写入到每一行中,行开头为父级区域,后面是子区域。
|
|
|
|
|
Iterator<String> keyIterator = map.keySet().iterator();
|
|
|
|
|
while (keyIterator.hasNext()) {
|
|
|
|
|
String key = keyIterator.next();
|
|
|
|
|
List<String> son = map.get(key);
|
|
|
|
|
Row row = hideSheet.createRow(rowId++);
|
|
|
|
|
row.createCell(0).setCellValue(key);
|
|
|
|
|
for (int i = 0; i < son.size(); i++) {
|
|
|
|
|
Cell cell = row.createCell(i+1);
|
|
|
|
|
cell.setCellValue(son.get(i));
|
|
|
|
|
}
|
|
|
|
|
// 添加名称管理器
|
|
|
|
|
String range = getRange(1, rowId, son.size());
|
|
|
|
|
Name name = workbook.createName();
|
|
|
|
|
name.setNameName(key);
|
|
|
|
|
String formula = "课程章节信息!" + range;
|
|
|
|
|
name.setRefersToFormula(formula);
|
|
|
|
|
}
|
|
|
|
|
//Iterator<String> keyIterator = map.keySet().iterator();
|
|
|
|
|
//while (keyIterator.hasNext()) {
|
|
|
|
|
// String key = keyIterator.next();
|
|
|
|
|
// List<String> son = map.get(key);
|
|
|
|
|
// Row row = hideSheet.createRow(rowId++);
|
|
|
|
|
// row.createCell(0).setCellValue(key);
|
|
|
|
|
// for (int i = 0; i < son.size(); i++) {
|
|
|
|
|
// Cell cell = row.createCell(i+1);
|
|
|
|
|
// cell.setCellValue(son.get(i));
|
|
|
|
|
// }
|
|
|
|
|
// // 添加名称管理器
|
|
|
|
|
// String range = getRange(1, rowId, son.size());
|
|
|
|
|
// Name name = workbook.createName();
|
|
|
|
|
// name.setNameName(key);
|
|
|
|
|
// String formula = "课程章节信息!" + range;
|
|
|
|
|
// name.setRefersToFormula(formula);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// 课程规则
|
|
|
|
|
// DVConstraint provConstraint = DVConstraint.createExplicitListConstraint(courseInfoArr.toArray(new String[] {}));
|
|
|
|
@ -515,26 +508,26 @@ public class ResourcesQuestionController{
|
|
|
|
|
// provinceDataValidation.createErrorBox("error", "请选择正确的课程");
|
|
|
|
|
// sheetPro.addValidationData(provinceDataValidation);
|
|
|
|
|
|
|
|
|
|
XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)sheetPro);
|
|
|
|
|
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(courseInfoArr.toArray(new String[] {}));
|
|
|
|
|
CellRangeAddressList addressList = new CellRangeAddressList(1, 20, 0, 0);
|
|
|
|
|
XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList);
|
|
|
|
|
validation.createErrorBox("error", "请选择正确的课程");
|
|
|
|
|
sheetPro.addValidationData(validation);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 对前200行设置有效性
|
|
|
|
|
for (int i = 2; i < 200; i++) {
|
|
|
|
|
setDataValidation("A", sheetPro, i, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if(null != is){
|
|
|
|
|
is.close();
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
//XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)sheetPro);
|
|
|
|
|
//XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(courseInfoArr.toArray(new String[] {}));
|
|
|
|
|
//CellRangeAddressList addressList = new CellRangeAddressList(1, 20, 0, 0);
|
|
|
|
|
//XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList);
|
|
|
|
|
//validation.createErrorBox("error", "请选择正确的课程");
|
|
|
|
|
//sheetPro.addValidationData(validation);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//// 对前200行设置有效性
|
|
|
|
|
//for (int i = 2; i < 200; i++) {
|
|
|
|
|
// setDataValidation("A", sheetPro, i, 2);
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//try {
|
|
|
|
|
// if(null != is){
|
|
|
|
|
// is.close();
|
|
|
|
|
// }
|
|
|
|
|
//}catch (Exception e){
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//准备将Excel的输出流通过response输出到页面下载
|
|
|
|
|
//八进制输出流
|
|
|
|
@ -558,7 +551,9 @@ public class ResourcesQuestionController{
|
|
|
|
|
if (null != response && null != response.getOutputStream()) {
|
|
|
|
|
response.getOutputStream().close();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) { }
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -632,8 +627,8 @@ public class ResourcesQuestionController{
|
|
|
|
|
//导入模板信息
|
|
|
|
|
@PostMapping(MODEL + "/importTemplate.json")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public JsonResult importTemplate(@RFile FileEntity fileEntity) {
|
|
|
|
|
return resourcesQuestionService.importTemplate(fileEntity);
|
|
|
|
|
public JsonResult importTemplate(@RFile FileEntity fileEntity,@SCoreUser CoreUser coreUser) {
|
|
|
|
|
return resourcesQuestionService.importTemplate(fileEntity,coreUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询客观题树结构
|
|
|
|
|