|
@@ -6,6 +6,9 @@ import java.util.*;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import cn.com.qmth.stmms.common.enums.*;
|
|
|
+import cn.com.qmth.stmms.common.utils.*;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
@@ -36,14 +40,6 @@ import cn.com.qmth.stmms.biz.mark.service.TaskService;
|
|
|
import cn.com.qmth.stmms.biz.user.model.User;
|
|
|
import cn.com.qmth.stmms.biz.user.service.UserService;
|
|
|
import cn.com.qmth.stmms.biz.user.service.query.UserSearchQuery;
|
|
|
-import cn.com.qmth.stmms.common.enums.ExamSubjectStatus;
|
|
|
-import cn.com.qmth.stmms.common.enums.LibraryStatus;
|
|
|
-import cn.com.qmth.stmms.common.enums.Role;
|
|
|
-import cn.com.qmth.stmms.common.enums.UserType;
|
|
|
-import cn.com.qmth.stmms.common.utils.DateUtils;
|
|
|
-import cn.com.qmth.stmms.common.utils.ExportExcel;
|
|
|
-import cn.com.qmth.stmms.common.utils.Md5EncryptUtils;
|
|
|
-import cn.com.qmth.stmms.common.utils.RequestUtils;
|
|
|
|
|
|
@Controller("examMarkerController")
|
|
|
@RequestMapping("/admin/exam-param/marker")
|
|
@@ -437,4 +433,97 @@ public class ExamMarkerController extends BaseParameterController {
|
|
|
}
|
|
|
return obj;
|
|
|
}
|
|
|
+ @RequestMapping(value = "/template")
|
|
|
+ public String importFileTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
|
|
|
+ try {
|
|
|
+ String fileName = "评卷员数据导入模板.xlsx";
|
|
|
+ List<Marker> list = Lists.newArrayList();
|
|
|
+ list.add(new Marker());
|
|
|
+ new ExportExcel("评卷员数据", Marker.class, 2).setDataList(list).write(response, fileName).dispose();
|
|
|
+ return null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ addMessage(redirectAttributes, "导入模板下载失败!失败信息:" + e.getMessage());
|
|
|
+ }
|
|
|
+ return "redirect:" + "/admin/exam-param/marker";
|
|
|
+ }
|
|
|
+ @RequestMapping(value = "/import", method = RequestMethod.POST)
|
|
|
+ public String importFile(HttpServletRequest request, MultipartFile file, RedirectAttributes redirectAttributes) {
|
|
|
+ int examId = getSessionExamId(request);
|
|
|
+ Exam exam = examService.findById(examId);
|
|
|
+ try {
|
|
|
+ int successNum = 0;
|
|
|
+ int failureNum = 0;
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ ImportExcel ei = new ImportExcel(file, 1, 0);
|
|
|
+ List<Marker> list = ei.getDataList(Marker.class);
|
|
|
+ List<Marker> saveList = new LinkedList<Marker>();
|
|
|
+ Map<String, Marker> saveMap = new HashMap<String, Marker>();
|
|
|
+ Map<String, ExamSubject> current = null;
|
|
|
+ current = new HashMap<String, ExamSubject>();
|
|
|
+ List<ExamSubject> list2 = subjectService.list(examId);
|
|
|
+ for (ExamSubject s : list2) {
|
|
|
+ current.put(s.getCode(), s);
|
|
|
+ }
|
|
|
+ for (Marker marker : list) {
|
|
|
+ String password = "";
|
|
|
+ if (StringUtils.isBlank(marker.getSubjectCode()) || StringUtils.isBlank(marker.getLoginName())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ marker.setExamId(examId);
|
|
|
+ marker.setName(marker.getLoginName());
|
|
|
+ marker.setEnable(true);
|
|
|
+ marker.setCommon(false);
|
|
|
+ if(StringUtils.isBlank(marker.getPassword())){
|
|
|
+ Random random = new Random();
|
|
|
+ for (int i=0;i<6;i++)
|
|
|
+ {
|
|
|
+ password+=random.nextInt(10);
|
|
|
+ }
|
|
|
+ marker.setPassword(password);
|
|
|
+ }
|
|
|
+ MarkerExcelError markerExcelError = checkLongNameAndPassword(marker,current,saveMap);
|
|
|
+ if (markerExcelError.equals(MarkerExcelError.MARKER)) {
|
|
|
+ saveList.add(marker);
|
|
|
+ saveMap.put(marker.getLoginName(), marker);
|
|
|
+ } else {
|
|
|
+ failureMsg.append("<br/>评卷员 " + marker.getLoginName() + ","+markerExcelError.getName());
|
|
|
+ failureNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ successNum = markerService.batchSave(saveList);
|
|
|
+ if (failureNum > 0) {
|
|
|
+ failureMsg.insert(0, ",失败 " + failureNum + " 条用户");
|
|
|
+ }
|
|
|
+ addMessage(redirectAttributes, "已成功导入 " + successNum + " 条评卷员" + failureMsg);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Batch import marker error!", e);
|
|
|
+ addMessage(redirectAttributes, "导入评卷员失败!失败信息:" + e.getMessage());
|
|
|
+ }
|
|
|
+ return "redirect:" + "/admin/exam-param/marker";
|
|
|
+ }
|
|
|
+ private MarkerExcelError checkLongNameAndPassword(Marker marker, Map<String, ExamSubject> current,Map<String, Marker> saveMap) {
|
|
|
+ Marker previous = null;
|
|
|
+
|
|
|
+ if(current != null && current.get(marker.getSubjectCode()) == null){
|
|
|
+ return MarkerExcelError.MARKERCODEMISS;
|
|
|
+ }
|
|
|
+ if (saveMap != null) {
|
|
|
+ previous = saveMap.get(marker.getLoginName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (previous != null) {
|
|
|
+ return MarkerExcelError.MARKERED;
|
|
|
+ }
|
|
|
+
|
|
|
+ previous = markerService.findByLoginName(marker.getLoginName());
|
|
|
+
|
|
|
+ if(marker.getPassword().length()>0 && marker.getPassword().length()<4){
|
|
|
+ return MarkerExcelError.MARKERPWERROR;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (previous == null) {
|
|
|
+ return MarkerExcelError.MARKER;
|
|
|
+ }
|
|
|
+ return MarkerExcelError.MARKERED;
|
|
|
+ }
|
|
|
}
|