|
@@ -1,18 +1,29 @@
|
|
package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
import java.util.Map.Entry;
|
|
|
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Example;
|
|
import org.springframework.data.domain.Example;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnum;
|
|
import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnum;
|
|
import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnumManager;
|
|
import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnumManager;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.helpers.poi.ExcelReader;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.DateUtil;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.DateUtil.DatePatterns;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.PathUtil;
|
|
import cn.com.qmth.examcloud.commons.web.enums.DataExecutionStatus;
|
|
import cn.com.qmth.examcloud.commons.web.enums.DataExecutionStatus;
|
|
import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
@@ -63,6 +74,9 @@ public class ExamServiceImpl implements ExamService {
|
|
@Autowired
|
|
@Autowired
|
|
DataSyncCloudService dataSyncCloudService;
|
|
DataSyncCloudService dataSyncCloudService;
|
|
|
|
|
|
|
|
+ private static final String[] EXAM_ORG_SETTINGS_EXCEL_HEADER = new String[]{"学习中心ID", "学习中心代码",
|
|
|
|
+ "学习中心名称", "是否可以考试", "开始考试时间", "结束考试时间"};
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 方法注释
|
|
* 方法注释
|
|
*
|
|
*
|
|
@@ -370,4 +384,165 @@ public class ExamServiceImpl implements ExamService {
|
|
|
|
|
|
return examPropertyEntity.getValue();
|
|
return examPropertyEntity.getValue();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Map<String, Object>> importExamOrgSettings(Long examId, File file) {
|
|
|
|
+
|
|
|
|
+ ExamEntity examEntity = examRepo.findOne(examId);
|
|
|
|
+ List<String[]> lineList = null;
|
|
|
|
+ try {
|
|
|
|
+ lineList = ExcelReader.readSheetBySax(PathUtil.getCanonicalPath(file), 1, 6);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new StatusException("B-200110", "Excel 解析失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isEmpty(lineList)) {
|
|
|
|
+ throw new StatusException("B-200111", "Excel无内容");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (10001 < lineList.size()) {
|
|
|
|
+ throw new StatusException("B-200112", "数据行数不能超过10000");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> failRecords = Collections
|
|
|
|
+ .synchronizedList(new ArrayList<Map<String, Object>>());
|
|
|
|
+ List<ExamOrgSettingsEntity> orgSettingsList = Lists.newArrayList();
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < lineList.size(); i++) {
|
|
|
|
+ String[] line = lineList.get(i);
|
|
|
|
+ if (0 == i) {
|
|
|
|
+ if (headerError(line)) {
|
|
|
|
+ throw new StatusException("B-100111", "Excel表头错误");
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ boolean hasError = false;
|
|
|
|
+ StringBuilder msg = new StringBuilder();
|
|
|
|
+
|
|
|
|
+ ExamOrgSettingsEntity orgSettings = new ExamOrgSettingsEntity();
|
|
|
|
+ orgSettings.setRootOrgId(examEntity.getRootOrgId());
|
|
|
|
+ orgSettings.setExamId(examId);
|
|
|
|
+
|
|
|
|
+ String orgId = trimAndNullIfBlank(line[0]);
|
|
|
|
+ if (StringUtils.isBlank(orgId)) {
|
|
|
|
+ msg.append(" 学习中心ID不能为空");
|
|
|
|
+ hasError = true;
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ long orgIdLong = Long.parseLong(orgId);
|
|
|
|
+
|
|
|
|
+ GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
|
+ getOrgReq.setOrgId(orgIdLong);
|
|
|
|
+ GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
|
+ OrgBean orgBean = getOrgResp.getOrg();
|
|
|
|
+
|
|
|
|
+ if (null != orgBean.getParentId()
|
|
|
|
+ || !orgBean.getRootId().equals(examEntity.getRootOrgId())) {
|
|
|
|
+ msg.append(" 学习中心ID非法");
|
|
|
|
+ hasError = true;
|
|
|
|
+ } else {
|
|
|
|
+ orgSettings.setOrgId(orgIdLong);
|
|
|
|
+ }
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ msg.append(" 学习中心ID必须为整数");
|
|
|
|
+ hasError = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String examLimit = trimAndNullIfBlank(line[3]);
|
|
|
|
+ if (StringUtils.isNotBlank(examLimit)) {
|
|
|
|
+ if (examLimit.equals("是")) {
|
|
|
|
+ orgSettings.setExamLimit(false);
|
|
|
|
+ } else if (examLimit.equals("否")) {
|
|
|
|
+ orgSettings.setExamLimit(true);
|
|
|
|
+ } else {
|
|
|
|
+ msg.append(" 是否可以开始考试必须为['是','否',空]");
|
|
|
|
+ hasError = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String beginTime = trimAndNullIfBlank(line[4]);
|
|
|
|
+ if (StringUtils.isNotBlank(beginTime)) {
|
|
|
|
+ try {
|
|
|
|
+ Date beginDate = DateUtil.parse(beginTime, DatePatterns.ISO);
|
|
|
|
+ orgSettings.setBeginTime(beginDate);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ msg.append(" 开始考试时间格式错误. 正确格式为 " + DatePatterns.ISO);
|
|
|
|
+ hasError = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String endTime = trimAndNullIfBlank(line[5]);
|
|
|
|
+ if (StringUtils.isNotBlank(endTime)) {
|
|
|
|
+ try {
|
|
|
|
+ Date endDate = DateUtil.parse(endTime, DatePatterns.ISO);
|
|
|
|
+ orgSettings.setBeginTime(endDate);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ msg.append(" 结束考试时间格式错误. 正确格式为 " + DatePatterns.ISO);
|
|
|
|
+ hasError = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (hasError) {
|
|
|
|
+ failRecords.add(newError(i + 1, msg.toString()));
|
|
|
|
+ } else {
|
|
|
|
+ orgSettingsList.add(orgSettings);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
|
+ return failRecords;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (ExamOrgSettingsEntity cur : orgSettingsList) {
|
|
|
|
+ ExamOrgSettingsEntity query = examOrgSettingsRepo.findByExamIdAndOrgId(examId,
|
|
|
|
+ cur.getOrgId());
|
|
|
|
+
|
|
|
|
+ if (null != query) {
|
|
|
|
+ query.setExamLimit(cur.getExamLimit());
|
|
|
|
+ query.setBeginTime(cur.getBeginTime());
|
|
|
|
+ query.setEndTime(cur.getEndTime());
|
|
|
|
+ examOrgSettingsRepo.save(query);
|
|
|
|
+ } else {
|
|
|
|
+ examOrgSettingsRepo.save(cur);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return failRecords;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Map<String, Object> newError(int lineNum, String msg) {
|
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
|
+ map.put("lineNum", lineNum);
|
|
|
|
+ map.put("msg", msg);
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String trimAndNullIfBlank(String s) {
|
|
|
|
+ if (StringUtils.isBlank(s)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return s.trim();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @param header
|
|
|
|
+ */
|
|
|
|
+ private boolean headerError(String[] header) {
|
|
|
|
+ for (int i = 0; i < EXAM_ORG_SETTINGS_EXCEL_HEADER.length; i++) {
|
|
|
|
+ if (null == header[i]) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (!EXAM_ORG_SETTINGS_EXCEL_HEADER[i].equals(header[i].trim())) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|