You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1302 lines
68 KiB
Java
1302 lines
68 KiB
Java
package com.ibeetl.jlw.service;
|
|
|
|
|
|
import cn.jlw.util.ToolUtils;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.ibeetl.admin.console.service.UserConsoleService;
|
|
import com.ibeetl.admin.core.entity.CoreUser;
|
|
import com.ibeetl.admin.core.service.CoreBaseService;
|
|
import com.ibeetl.admin.core.service.CorePlatformService;
|
|
import com.ibeetl.admin.core.util.PlatformException;
|
|
import com.ibeetl.admin.core.util.TimeTool;
|
|
import com.ibeetl.admin.core.web.JsonResult;
|
|
import com.ibeetl.admin.core.web.JsonReturnCode;
|
|
import com.ibeetl.jlw.dao.StudentDao;
|
|
import com.ibeetl.jlw.entity.*;
|
|
import com.ibeetl.jlw.job.CacheLogJob;
|
|
import com.ibeetl.jlw.web.query.*;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
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.xssf.usermodel.XSSFWorkbook;
|
|
import org.beetl.sql.core.SqlId;
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.io.*;
|
|
import java.math.BigDecimal;
|
|
import java.text.DateFormat;
|
|
import java.text.DecimalFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Future;
|
|
import java.util.stream.Collectors;
|
|
|
|
import static com.ibeetl.jlw.web.IpAddressController.ipAddressMap;
|
|
|
|
|
|
/**
|
|
* Student Service
|
|
*/
|
|
|
|
@Service
|
|
@Transactional
|
|
public class StudentService extends CoreBaseService<Student>{
|
|
|
|
@Resource private StudentDao studentDao;
|
|
@Resource private StudentQuestionLogService studentQuestionLogService;
|
|
@Resource private StudentQuestionLogInfoService studentQuestionLogInfoService;
|
|
@Resource private StudentQuestionLogAnswerService studentQuestionLogAnswerService;
|
|
@Resource private WrongQuestionService wrongQuestionService;
|
|
|
|
@Resource CorePlatformService platformService;
|
|
|
|
@Resource UserConsoleService userConsoleService;
|
|
|
|
@Resource SchoolClassService schoolClassService;
|
|
|
|
@Resource private CompetitionService competitionService;
|
|
@Resource private CompetitionStudentsService competitionStudentsService;
|
|
@Resource private CompetitionTaskOneQuestionService competitionTaskOneQuestionService;
|
|
@Resource private CompetitionTaskSecondQuestionService competitionTaskSecondQuestionService;
|
|
@Resource private CompetitionTaskSecondQuestionStepService competitionTaskSecondQuestionStepService;
|
|
|
|
@Resource private ExamService examService;
|
|
@Resource private ExamStudentsService examStudentsService;
|
|
@Resource private ExamTaskOneQuestionService examTaskOneQuestionService;
|
|
@Resource private ExamTaskSecondQuestionService examTaskSecondQuestionService;
|
|
@Resource private ExamTaskSecondQuestionStepService examTaskSecondQuestionStepService;
|
|
@Resource private ExamTaskThreeQuestionService examTaskThreeQuestionService;
|
|
@Resource private ExamTaskThreeQuestionStepService examTaskThreeQuestionStepService;
|
|
|
|
@Resource private ResourcesQuestionService resourcesQuestionService;
|
|
|
|
@Resource private CourseInfoService courseInfoService;
|
|
|
|
@Resource private StudentDefenceLogService studentDefenceLogService;
|
|
@Resource private StudentDefenceLogInfoService studentDefenceLogInfoService;
|
|
@Resource private StudentDefenceLogNoteService studentDefenceLogNoteService;
|
|
|
|
|
|
private ExecutorService pool = Executors.newCachedThreadPool();
|
|
|
|
public PageQuery<Student>queryByCondition(PageQuery query){
|
|
PageQuery ret = studentDao.queryByCondition(query);
|
|
queryListAfter(ret.getList());
|
|
return ret;
|
|
}
|
|
|
|
public PageQuery<Student>queryLogByCondition(PageQuery query){
|
|
PageQuery ret = studentDao.queryByCondition(query);
|
|
queryListAfter(ret.getList());
|
|
|
|
String studentIds = "";
|
|
List<Student> studentList = ret.getList();
|
|
for(int i=0;i<studentList.size();i++){
|
|
studentIds += studentList.get(i).getStudentId()+",";
|
|
}
|
|
|
|
Map<String, List<Student>> groupByStudentId = CacheLogJob.studentLogMap;
|
|
|
|
if((null == groupByStudentId || groupByStudentId.size() == 0)&& StringUtils.isNotBlank(studentIds)){
|
|
StudentQuery studentQuery = new StudentQuery();
|
|
studentQuery.setStudentIds(studentIds);
|
|
List<Student> studentLogList = getStudentLog(studentQuery);
|
|
try{
|
|
groupByStudentId = studentLogList.stream().collect(Collectors.groupingBy(e -> (null != e.get("platform")&&StringUtils.isNotBlank(e.get("platform").toString())?e.get("platform").toString():"null")+e.getStudentId()));
|
|
}catch (Exception e){}
|
|
}
|
|
|
|
if(null != groupByStudentId){
|
|
for(int i=0;i<studentList.size();i++){
|
|
List<Student> studentLogList = groupByStudentId.get((null != studentList.get(i).get("platform")&&StringUtils.isNotBlank(studentList.get(i).get("platform").toString())?studentList.get(i).get("platform").toString():"null")+studentList.get(i).getStudentId());
|
|
if(null != studentLogList && studentLogList.size()>0){
|
|
Student studentLog = studentLogList.get(0);
|
|
studentList.get(i).set("lastLoginTime",studentLog.get("lastLoginTime"));
|
|
studentList.get(i).set("onlineDuration",TimeTool.diffTime(studentLog.get("lastLoginTime"),studentLog.get("lastOperateTime")));
|
|
studentList.get(i).set("ip",studentLog.get("ip"));
|
|
IpAddress ipAddress = null != studentLog.get("ip") && StringUtils.isNotBlank(studentLog.get("ip").toString())?ipAddressMap.get(studentLog.get("ip").toString()):null;
|
|
studentList.get(i).set("ipAddress",null != ipAddress?(ipAddress.getProvince()+ipAddress.getCity()+ipAddress.getDistrict()):null);//IP地址
|
|
}else {
|
|
studentList.get(i).set("lastLoginTime",null);
|
|
studentList.get(i).set("onlineDuration",null);
|
|
studentList.get(i).set("ip",null);
|
|
studentList.get(i).set("ipAddress",null);
|
|
}
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
public PageQuery<Student>queryPracticePerformanceStatistic(PageQuery query){
|
|
PageQuery ret = studentDao.getPracticePerformanceStatistic(query);
|
|
queryListAfter(ret.getList());
|
|
return ret;
|
|
}
|
|
|
|
public List<CourseInfo> getPracticePerformanceStatisticInfoList(StudentQuery studentQuery){
|
|
|
|
String courseInfoIds = "";
|
|
List<CourseInfo> courseInfoList = new ArrayList<>();
|
|
|
|
CourseInfo courseInfo = courseInfoService.getTreeById(studentQuery.getCourseInfoId());
|
|
List<CourseInfo> childrenList = courseInfo.takeChildren();
|
|
for(int i=0;null != childrenList && i<childrenList.size();i++){
|
|
courseInfoList.add(childrenList.get(i));
|
|
courseInfoIds += childrenList.get(i).getCourseInfoId()+",";
|
|
List<CourseInfo> childrenChildrenList = childrenList.get(i).takeChildren();
|
|
for(int j=0;j<childrenChildrenList.size();j++){
|
|
courseInfoList.add(childrenChildrenList.get(j));
|
|
courseInfoIds += childrenChildrenList.get(j).getCourseInfoId()+",";
|
|
List<CourseInfo> childrenChildrenChildrenList = childrenChildrenList.get(j).takeChildren();
|
|
for(int k=0;k<childrenChildrenChildrenList.size();k++){
|
|
childrenChildrenChildrenList.get(k).setCourseInfoName(" "+childrenChildrenChildrenList.get(k).getCourseInfoName());
|
|
courseInfoList.add(childrenChildrenChildrenList.get(k));
|
|
courseInfoIds += childrenChildrenChildrenList.get(k).getCourseInfoId()+",";
|
|
List<CourseInfo> childrenChildrenChildrenChildrenList = childrenChildrenChildrenList.get(k).takeChildren();
|
|
for(int l=0;l<childrenChildrenChildrenChildrenList.size();l++){
|
|
childrenChildrenChildrenList.get(k).setCourseInfoName("  "+childrenChildrenChildrenList.get(k).getCourseInfoName());
|
|
courseInfoList.add(childrenChildrenChildrenChildrenList.get(l));
|
|
courseInfoIds += childrenChildrenChildrenChildrenList.get(l).getCourseInfoId()+",";
|
|
}
|
|
}
|
|
}
|
|
childrenList.get(i).putChildren(new ArrayList<>());
|
|
}
|
|
|
|
Map<Long, List<Student>> groupByCourseInfoId = null;
|
|
|
|
if(StringUtils.isNotBlank(courseInfoIds)){
|
|
StudentQuery query = new StudentQuery();
|
|
query.setCourseInfoIds(courseInfoIds);
|
|
query.setStudentId(studentQuery.getStudentId());
|
|
query.setOrgId(studentQuery.getOrgId());
|
|
List<Student> studentLogList = getPracticePerformanceStatisticInfo(query);
|
|
try{
|
|
groupByCourseInfoId = studentLogList.stream().collect(Collectors.groupingBy(e -> Long.parseLong(null != e.get("courseInfoId")?e.get("courseInfoId").toString():"-1")));
|
|
}catch (Exception e){}
|
|
}
|
|
|
|
if(null != groupByCourseInfoId){
|
|
for(int i=0;i<childrenList.size();i++){
|
|
List<Student> studentLogList = groupByCourseInfoId.get(childrenList.get(i).getCourseInfoId());
|
|
if(null != studentLogList && studentLogList.size()>0){
|
|
Student studentLog = studentLogList.get(0);
|
|
childrenList.get(i).set("resourcesQuestionNum",studentLog.get("resourcesQuestionNum"));
|
|
childrenList.get(i).set("resourcesCompetitionNum",studentLog.get("resourcesCompetitionNum"));
|
|
childrenList.get(i).set("resourcesTrainingNum",studentLog.get("resourcesTrainingNum"));
|
|
childrenList.get(i).set("resourcesQuestionProportion",studentLog.get("resourcesQuestionProportion"));
|
|
childrenList.get(i).set("resourcesCompetitionProportion",studentLog.get("resourcesCompetitionProportion"));
|
|
childrenList.get(i).set("resourcesTrainingProportion",studentLog.get("resourcesTrainingProportion"));
|
|
}else {
|
|
childrenList.get(i).set("resourcesQuestionNum",null);
|
|
childrenList.get(i).set("resourcesCompetitionNum",null);
|
|
childrenList.get(i).set("resourcesTrainingNum",null);
|
|
childrenList.get(i).set("resourcesQuestionProportion",null);
|
|
childrenList.get(i).set("resourcesCompetitionProportion",null);
|
|
childrenList.get(i).set("resourcesTrainingProportion",null);
|
|
}
|
|
}
|
|
}
|
|
|
|
return childrenList;
|
|
}
|
|
|
|
|
|
public List<CourseInfo> getPracticeProgressList(StudentQuery studentQuery){
|
|
|
|
String courseInfoIds = "";
|
|
List<CourseInfo> courseInfoList = new ArrayList<>();
|
|
|
|
CourseInfo courseInfo = courseInfoService.getTreeById(studentQuery.getCourseInfoId());
|
|
List<CourseInfo> childrenList = courseInfo.takeChildren();
|
|
for(int i=0;null != childrenList && i<childrenList.size();i++){
|
|
courseInfoList.add(childrenList.get(i));
|
|
courseInfoIds += childrenList.get(i).getCourseInfoId()+",";
|
|
List<CourseInfo> childrenChildrenList = childrenList.get(i).takeChildren();
|
|
for(int j=0;j<childrenChildrenList.size();j++){
|
|
courseInfoList.add(childrenChildrenList.get(j));
|
|
courseInfoIds += childrenChildrenList.get(j).getCourseInfoId()+",";
|
|
List<CourseInfo> childrenChildrenChildrenList = childrenChildrenList.get(j).takeChildren();
|
|
for(int k=0;k<childrenChildrenChildrenList.size();k++){
|
|
childrenChildrenChildrenList.get(k).setCourseInfoName(" "+childrenChildrenChildrenList.get(k).getCourseInfoName());
|
|
courseInfoList.add(childrenChildrenChildrenList.get(k));
|
|
courseInfoIds += childrenChildrenChildrenList.get(k).getCourseInfoId()+",";
|
|
List<CourseInfo> childrenChildrenChildrenChildrenList = childrenChildrenChildrenList.get(k).takeChildren();
|
|
for(int l=0;l<childrenChildrenChildrenChildrenList.size();l++){
|
|
childrenChildrenChildrenList.get(k).setCourseInfoName("  "+childrenChildrenChildrenList.get(k).getCourseInfoName());
|
|
courseInfoList.add(childrenChildrenChildrenChildrenList.get(l));
|
|
courseInfoIds += childrenChildrenChildrenChildrenList.get(l).getCourseInfoId()+",";
|
|
}
|
|
}
|
|
}
|
|
childrenList.get(i).putChildren(new ArrayList<>());
|
|
}
|
|
|
|
Map<Long, List<Student>> groupByCourseInfoId = null;
|
|
|
|
if(StringUtils.isNotBlank(courseInfoIds)){
|
|
StudentQuery query = new StudentQuery();
|
|
query.setCourseInfoIds(courseInfoIds);
|
|
query.setStudentId(studentQuery.getStudentId());
|
|
query.setClassId(studentQuery.getClassId());
|
|
query.setOrgId(studentQuery.getOrgId());
|
|
List<Student> studentLogList = getPracticeProgress(query);
|
|
try{
|
|
groupByCourseInfoId = studentLogList.stream().collect(Collectors.groupingBy(e -> Long.parseLong(null != e.get("courseInfoId")?e.get("courseInfoId").toString():"-1")));
|
|
}catch (Exception e){}
|
|
}
|
|
|
|
if(null != groupByCourseInfoId){
|
|
for(int i=0;i<childrenList.size();i++){
|
|
List<Student> studentLogList = groupByCourseInfoId.get(childrenList.get(i).getCourseInfoId());
|
|
if(null != studentLogList && studentLogList.size()>0){
|
|
Student studentLog = studentLogList.get(0);
|
|
childrenList.get(i).set("resourcesQuestionNum",studentLog.get("resourcesQuestionNum"));
|
|
childrenList.get(i).set("resourcesCompetitionNum",studentLog.get("resourcesCompetitionNum"));
|
|
childrenList.get(i).set("resourcesTrainingNum",studentLog.get("resourcesTrainingNum"));
|
|
childrenList.get(i).set("resourcesQuestionProportion",studentLog.get("resourcesQuestionProportion"));
|
|
childrenList.get(i).set("resourcesCompetitionProportion",studentLog.get("resourcesCompetitionProportion"));
|
|
childrenList.get(i).set("resourcesTrainingProportion",studentLog.get("resourcesTrainingProportion"));
|
|
}else {
|
|
childrenList.get(i).set("resourcesQuestionNum",null);
|
|
childrenList.get(i).set("resourcesCompetitionNum",null);
|
|
childrenList.get(i).set("resourcesTrainingNum",null);
|
|
childrenList.get(i).set("resourcesQuestionProportion",null);
|
|
childrenList.get(i).set("resourcesCompetitionProportion",null);
|
|
childrenList.get(i).set("resourcesTrainingProportion",null);
|
|
}
|
|
}
|
|
}
|
|
|
|
return childrenList;
|
|
}
|
|
|
|
|
|
|
|
public PageQuery<Student>queryByCondition2Student(PageQuery query){
|
|
PageQuery ret = studentDao.queryByCondition2Student(query);
|
|
queryListAfter(ret.getList());
|
|
return ret;
|
|
}
|
|
|
|
public List<Student> getStudentLog (StudentQuery studentQuery){
|
|
return studentDao.getStudentLog(studentQuery);
|
|
}
|
|
|
|
public List<Student> getPracticePerformanceStatisticInfo (StudentQuery studentQuery){
|
|
return studentDao.getPracticePerformanceStatisticInfo(studentQuery);
|
|
}
|
|
|
|
public List<Student> getPracticeProgress (StudentQuery studentQuery){
|
|
return studentDao.getPracticeProgress(studentQuery);
|
|
}
|
|
|
|
public PageQuery<CourseInfo> getErrorStatistics (PageQuery query){
|
|
PageQuery ret = studentDao.getErrorStatistics(query);
|
|
queryListAfter(ret.getList());
|
|
return ret;
|
|
}
|
|
|
|
public void deleteStudent(String ids){
|
|
|
|
String userIds = "";
|
|
List<Student> studentList = studentDao.getByIds(ids);
|
|
for(int i=0;i<studentList.size();i++){
|
|
userIds += studentList.get(i).getUserId() + ",";
|
|
}
|
|
|
|
//置空相应coreUser的code
|
|
userConsoleService.batchSetCodeNullByIds(userIds);
|
|
|
|
studentDao.deleteStudentByIds(ids);
|
|
|
|
}
|
|
|
|
public void deleteByList(List list){
|
|
String ids = "";
|
|
for(int i=0;null != list &&i<list.size();i++){
|
|
ids += list.get(i).toString()+",";
|
|
}
|
|
if(StringUtils.isNotBlank(ids)){
|
|
studentDao.deleteByIds(ids);
|
|
}
|
|
}
|
|
|
|
public JsonResult add(Student student){
|
|
|
|
Date date = new Date();
|
|
|
|
student.setStudentPassword(StringUtils.isNotBlank(student.getStudentPassword())?student.getStudentPassword():"123qwe");
|
|
student.setAddTime(date);
|
|
student.setStudentStatus(1);
|
|
this.save(student);
|
|
String code = student.createCode();
|
|
|
|
if (!platformService.isAllowUserCode(code)) {
|
|
throw new PlatformException("不允许的注册账号 " + code);
|
|
}
|
|
CoreUser coreUser = new CoreUser();
|
|
coreUser.setName(student.getStudentName());
|
|
coreUser.setCode(student.getStudentSn());
|
|
coreUser.setJobType0("JT_02");
|
|
coreUser.setJobType1("JT_S_03");
|
|
coreUser.setState("S1");
|
|
coreUser.setDelFlag(0);
|
|
coreUser.setCreateTime(date);
|
|
SchoolClass schoolClass = schoolClassService.queryById(student.getClassId());
|
|
coreUser.setOrgId(schoolClass.getOrgId());
|
|
coreUser.setPassword(StringUtils.isNotBlank(student.getStudentPassword())?student.getStudentPassword():"123qwe");
|
|
|
|
userConsoleService.saveUser(coreUser);
|
|
|
|
Student s = new Student();
|
|
s.setStudentId(student.getStudentId());
|
|
s.setUserId(coreUser.getId());
|
|
s.setOrgId(schoolClass.getOrgId());
|
|
|
|
this.updateTemplate(s);
|
|
|
|
JsonResult jsonResult = new JsonResult();
|
|
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
jsonResult.setData(student.getStudentId());
|
|
jsonResult.setMsg("添加成功");
|
|
|
|
return jsonResult;
|
|
}
|
|
|
|
public Boolean edit(Student student){
|
|
SchoolClass schoolClass = schoolClassService.queryById(student.getClassId());
|
|
student.setOrgId(schoolClass.getOrgId());
|
|
this.updateTemplate(student);
|
|
student = this.queryById(student.getStudentId());
|
|
String code = student.createCode();//TODO 可改规则
|
|
|
|
if (!platformService.isAllowUserCode(student.getUserId(),code)) {
|
|
throw new PlatformException("不允许的注册账号 " + code);
|
|
}
|
|
CoreUser coreUser = new CoreUser();
|
|
coreUser.setId(student.getUserId());
|
|
coreUser.setCode(code);
|
|
|
|
userConsoleService.updateTemplate(coreUser);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
public Boolean initPassword(Student student){
|
|
Student s = this.queryById(student.getStudentId());
|
|
|
|
CoreUser coreUser = new CoreUser();
|
|
coreUser.setId(s.getUserId());
|
|
coreUser.setPassword("123qwe");
|
|
userConsoleService.updateTemplate(coreUser);
|
|
platformService.clearFunctionCache();
|
|
|
|
return true;
|
|
}
|
|
|
|
public JsonResult importTemplate(FileEntity fileEntity,List<Long>delList,List<String> list){
|
|
if(null != fileEntity){
|
|
File file = new File(fileEntity.getAbsoluteUrl());
|
|
if(file.exists() && file.isFile() && file.canRead() && ToolUtils.findInSet("xls,xlsx",fileEntity.getFormat())){
|
|
|
|
Workbook wb = null;
|
|
InputStream is = null;
|
|
try {
|
|
is = new FileInputStream(fileEntity.getAbsoluteUrl());
|
|
if("xls".equals(fileEntity.getFormat())){
|
|
wb = new HSSFWorkbook(is);
|
|
}else if("xlsx".equals(fileEntity.getFormat())){
|
|
wb = new XSSFWorkbook(is);
|
|
}
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
try {
|
|
if(null != is){
|
|
is.close();
|
|
}
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
|
|
if(wb != null){
|
|
List<String[]> errMsg = new ArrayList<>();
|
|
String msg ="";
|
|
|
|
//获取Sheet1
|
|
Sheet sheet = wb.getSheet("Sheet1");
|
|
//获取最大行数
|
|
int rowNum = sheet.getPhysicalNumberOfRows();
|
|
//获取第一行
|
|
Row firstRow = sheet.getRow(0);
|
|
//获取最大列数
|
|
int colNum = firstRow.getPhysicalNumberOfCells();
|
|
|
|
String columns[] = {"院校名称","班级名称","学生姓名","学号","电话","邮箱"};
|
|
|
|
Map<String,Integer> map = new HashMap<>();//获取需要的表头的列
|
|
|
|
//从第一列找到需要的表头
|
|
for (int i=0; i<colNum; i++){
|
|
String cellData = getCellFormatValue(firstRow.getCell(i));
|
|
for(int j=0;j<columns.length;j++){
|
|
if(columns[j].equals(cellData)){
|
|
map.put(columns[j],i);
|
|
}
|
|
}
|
|
}
|
|
|
|
//验证所需要的表头是否全
|
|
Integer flag = 0;
|
|
for(int i=0;i<columns.length;i++){
|
|
if(null != map.get(columns[i])){
|
|
flag ++;
|
|
}
|
|
}
|
|
if(flag != columns.length){
|
|
return JsonResult.failMessage("导入失败,表格表头应包含 \"院校名称\",\"班级名称\",\"学生姓名\",\"学号\",\"电话\",\"邮箱\"");
|
|
}
|
|
|
|
int count = 0;
|
|
|
|
Date date = new Date();
|
|
|
|
for (int i = 1; i<rowNum; i++) {
|
|
Row row = sheet.getRow(i);
|
|
if(null == row){
|
|
// msg += "第"+(i+1)+"数据为空<br>";
|
|
errMsg.add(new String[]{"第"+(i+1)+"数据为空"});
|
|
continue;
|
|
}
|
|
|
|
String className = getCellFormatValue(row.getCell(map.get(columns[1])));
|
|
String studentName = getCellFormatValue(row.getCell(map.get(columns[2])));
|
|
String studentSn = getCellFormatValue(row.getCell(map.get(columns[3])));
|
|
String studentMobile = getCellFormatValue(row.getCell(map.get(columns[4])));
|
|
String studentEmail = getCellFormatValue(row.getCell(map.get(columns[5])));
|
|
|
|
if(StringUtils.isBlank(className)){
|
|
// msg += "第"+ToolUtils.numberToLetter(map.get(columns[1])+1)+"列,第"+(i+1)+"行班级名称为空<br>";
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[1])+1)+"列,第"+(i+1)+"行班级名称为空"});
|
|
continue;
|
|
}else if(StringUtils.isBlank(studentName)){
|
|
// msg += "第"+ToolUtils.numberToLetter(map.get(columns[2])+1)+"列,第"+(i+1)+"行学生姓名为空<br>";
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[2])+1)+"列,第"+(i+1)+"行学生姓名为空"});
|
|
continue;
|
|
}else if(StringUtils.isBlank(studentSn)){
|
|
// msg += "第"+ToolUtils.numberToLetter(map.get(columns[3])+1)+"列,第"+(i+1)+"行学号为空<br>";
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[3])+1)+"列,第"+(i+1)+"行学号为空"});
|
|
continue;
|
|
}else if(className.split("_").length != 2){
|
|
// msg += "第"+ToolUtils.numberToLetter(map.get(columns[1])+1)+"列,第"+(i+1)+"行班级ID丢失<br>";
|
|
errMsg.add(new String[]{"第"+ToolUtils.numberToLetter(map.get(columns[1])+1)+"列,第"+(i+1)+"行班级ID丢失"});
|
|
continue;
|
|
}else {
|
|
|
|
Student pojo = new Student();
|
|
|
|
pojo.setClassId(Long.parseLong(className.split("_")[1]));
|
|
pojo.setStudentName(studentName);
|
|
pojo.setStudentSn(studentSn);
|
|
pojo.setStudentMobile(studentMobile);
|
|
pojo.setStudentEmail(studentEmail);
|
|
pojo.setStudentStatus(1);
|
|
pojo.setStudentPassword("123qwe");
|
|
pojo.setAddTime(date);
|
|
|
|
save(pojo);
|
|
|
|
String code = pojo.createCode();//TODO 可改规则
|
|
|
|
if (!platformService.isAllowUserCode(code)) {
|
|
delList.add(pojo.getStudentId());
|
|
// msg += "第"+(i+1)+"行不允许的注册账号 "+code+"<br>";
|
|
errMsg.add(new String[]{"第"+(i+1)+"行不允许的注册账号 "+code});
|
|
}else {
|
|
|
|
{
|
|
Student s = new Student();
|
|
s.setClassId(Long.parseLong(className.split("_")[1]));
|
|
s.setStudentName(studentName);
|
|
if(studentDao.template(s).size()>1){
|
|
errMsg.add(new String[]{"第"+(i+1)+"行存在同名同姓的学生,姓名 "+studentName+" 是否删除",pojo.getStudentId().toString()});
|
|
}
|
|
}
|
|
|
|
CoreUser coreUser = new CoreUser();
|
|
coreUser.setName(pojo.getStudentName());
|
|
coreUser.setCode(code);
|
|
coreUser.setJobType0("JT_02");
|
|
coreUser.setJobType1("JT_S_03");
|
|
coreUser.setState("S1");
|
|
coreUser.setDelFlag(0);
|
|
coreUser.setCreateTime(date);
|
|
SchoolClass schoolClass = schoolClassService.queryById(pojo.getClassId());
|
|
coreUser.setOrgId(schoolClass.getOrgId());
|
|
coreUser.setPassword("123qwe");
|
|
userConsoleService.saveUser(coreUser);
|
|
|
|
Student s = new Student();
|
|
s.setStudentId(pojo.getStudentId());
|
|
s.setStudentSn(studentSn);
|
|
s.setUserId(coreUser.getId());
|
|
s.setOrgId(schoolClass.getOrgId());
|
|
|
|
this.updateTemplate(s);
|
|
|
|
if(list.size()==0){
|
|
list.add(s.getStudentId()+",");
|
|
}else {
|
|
String str = list.get(0) + s.getStudentId()+",";
|
|
list.add(str);
|
|
list.remove(0);
|
|
}
|
|
|
|
count ++;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(count>0){
|
|
JsonResult jsonResult = new JsonResult();
|
|
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
jsonResult.setData(errMsg);
|
|
jsonResult.setMsg("导入成功,共导入"+count+"条"+(StringUtils.isNotBlank(msg)?"<br>"+msg:""));
|
|
return jsonResult;
|
|
}else {
|
|
return JsonResult.failMessage("导入失败"+(StringUtils.isNotBlank(msg)?"<br>"+msg:""));
|
|
}
|
|
}
|
|
return JsonResult.failMessage("导入失败");
|
|
}else {
|
|
return JsonResult.failMessage("上传失败");
|
|
}
|
|
}else {
|
|
return JsonResult.failMessage("上传失败");
|
|
}
|
|
}
|
|
|
|
public String getCellFormatValue(Cell cell) {
|
|
String value = null;
|
|
if (cell != null){
|
|
switch (cell.getCellTypeEnum()) {
|
|
case STRING:
|
|
value = cell.getRichStringCellValue().getString();
|
|
break;
|
|
case NUMERIC:
|
|
String dataFormatString = cell.getCellStyle().getDataFormatString();
|
|
if ("m/d/yy".equals(dataFormatString) || "yyyy-mm-dd".equals(dataFormatString)) {
|
|
DateFormat df = new SimpleDateFormat(dataFormatString);
|
|
value = TimeTool.getNowTime(df.format(cell.getDateCellValue()));
|
|
} else {
|
|
DecimalFormat df = new DecimalFormat("#");
|
|
value = df.format(cell.getNumericCellValue());
|
|
}
|
|
break;
|
|
case BOOLEAN:
|
|
value = String.valueOf(cell.getBooleanCellValue());
|
|
break;
|
|
case FORMULA:
|
|
value = cell.getCellFormula();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
|
|
public List<Map<String,Object>> getExcelValues2Competition (StudentQuery studentQuery){
|
|
return studentDao.getExcelValues2Competition(studentQuery);
|
|
}
|
|
|
|
public List<Map<String,Object>> getExcelValues (StudentQuery studentQuery){
|
|
return studentDao.getExcelValues(studentQuery);
|
|
}
|
|
|
|
public Student getByUserId(Long userId){
|
|
return studentDao.getByUserId(userId);
|
|
}
|
|
|
|
public Student getByAccount(String account){
|
|
return studentDao.getByAccount(account);
|
|
}
|
|
|
|
public List<Student> getByIds (String studentIds){
|
|
return studentDao.getByIds(studentIds);
|
|
}
|
|
|
|
public List<Student> getValues (Object paras){
|
|
return sqlManager.select(SqlId.of("jlw.student.getStudentValues"), Student.class, paras);
|
|
}
|
|
|
|
public List<Student> getValuesByQuery (StudentQuery studentQuery){
|
|
return studentDao.getValuesByQuery(studentQuery);
|
|
}
|
|
|
|
//大赛任务一答卷
|
|
public JsonResult updateCT1QuestionAnswer(CompetitionTaskOneQuestionQuery condition,Student student){
|
|
if(null == condition.getCompetitionId()){
|
|
return JsonResult.failMessage("参数丢失");
|
|
}
|
|
if(null == student){
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
}
|
|
Competition competition = competitionService.getById(condition.getCompetitionId());
|
|
|
|
CompetitionStudents cs = new CompetitionStudents();
|
|
cs.setCompetitionId(competition.getCompetitionId());
|
|
cs.setStudentsId(student.getStudentId());
|
|
cs = competitionStudentsService.getValues(cs).get(0);
|
|
|
|
//对于交卷 加1分钟做缓冲
|
|
if(((Integer)1).equals(condition.getBeSubmitted()) && null != competition && competition.getCompetitionTaskOneEndTime().getTime() < System.currentTimeMillis() - 60000 ){
|
|
return JsonResult.failMessage("提交失败,大赛任务一已结束");
|
|
}else if(!((Integer)1).equals(condition.getBeSubmitted()) && null != cs && cs.getCompetitionTaskOneFinishTime() != null && cs.getCompetitionTaskOneFinishTime().getTime() < System.currentTimeMillis()){
|
|
return JsonResult.failMessage("提交失败,已交卷");
|
|
}else if(!((Integer)1).equals(condition.getBeSubmitted()) && null != competition && competition.getCompetitionTaskOneEndTime().getTime() < System.currentTimeMillis()){
|
|
return JsonResult.failMessage("提交失败,大赛任务一已结束");
|
|
}
|
|
|
|
CompetitionTaskOneQuestionQuery ct1QQuery = new CompetitionTaskOneQuestionQuery();
|
|
ct1QQuery.setCompetitionId(condition.getCompetitionId());
|
|
ct1QQuery.setStudentsId(student.getStudentId());
|
|
List<CompetitionTaskOneQuestion> oldCT1QuestionList = competitionTaskOneQuestionService.getValuesByQuery(ct1QQuery);
|
|
Map<Long, List<CompetitionTaskOneQuestion>> groupByCT1QId = null;
|
|
try{
|
|
groupByCT1QId = oldCT1QuestionList.stream().collect(Collectors.groupingBy(e -> e.getCompetitionTaskOneQuestionId()));
|
|
}catch (Exception e){}
|
|
if(null == groupByCT1QId){
|
|
return JsonResult.failMessage("数据有误,请联系管理员");
|
|
}
|
|
|
|
if(StringUtils.isNotBlank(condition.getCT1QuestionMapJson())){
|
|
Map<String,JSONObject> cT1QuestionMap = new HashMap<>();
|
|
try {
|
|
cT1QuestionMap = (JSONObject.parseObject(condition.getCT1QuestionMapJson(), HashMap.class));
|
|
} catch (Exception e) {}
|
|
List<CompetitionTaskOneQuestion>competitionTaskOneQuestionList = new ArrayList<>();
|
|
|
|
for(Map.Entry<String,JSONObject> entry:cT1QuestionMap.entrySet()){
|
|
CompetitionTaskOneQuestionQuery ct1qq = JSONObject.toJavaObject(entry.getValue(),CompetitionTaskOneQuestionQuery.class);
|
|
if(null != ct1qq && StringUtils.isNotBlank(ct1qq.getStudentAnswer()) && StringUtils.isNotBlank(ct1qq.getAddTime())){
|
|
if(TimeTool.getTime(ct1qq.getAddTime()).getTime() <= competition.getCompetitionTaskOneEndTime().getTime()){
|
|
CompetitionTaskOneQuestion competitionTaskOneQuestion = new CompetitionTaskOneQuestion();
|
|
if(null == groupByCT1QId.get(Long.parseLong(entry.getKey()))){//判断答案和提交学员是否统一
|
|
continue;
|
|
}
|
|
competitionTaskOneQuestion.setCompetitionTaskOneQuestionId(ct1qq.getCompetitionTaskOneQuestionId());
|
|
competitionTaskOneQuestion.setStudentAnswer(resourcesQuestionService.answerFormat(groupByCT1QId.get(Long.parseLong(entry.getKey())).get(0).getQuestionType(),ct1qq.getStudentAnswer()));
|
|
competitionTaskOneQuestionList.add(competitionTaskOneQuestion);
|
|
}
|
|
}
|
|
}
|
|
if(competitionTaskOneQuestionList.size()>0){
|
|
competitionTaskOneQuestionService.updateBatchTemplate(competitionTaskOneQuestionList);
|
|
}
|
|
}else {
|
|
if(null != condition.getCompetitionTaskOneQuestionId() && StringUtils.isNotBlank(condition.getStudentAnswer()) && StringUtils.isNotBlank(condition.getAddTime())){
|
|
if(TimeTool.getTime(condition.getAddTime()).getTime() <= competition.getCompetitionTaskOneEndTime().getTime()){
|
|
CompetitionTaskOneQuestion competitionTaskOneQuestion = new CompetitionTaskOneQuestion();
|
|
if(null != groupByCT1QId.get(condition.getCompetitionTaskOneQuestionId())){//判断答案和提交学员是否统一
|
|
competitionTaskOneQuestion.setCompetitionTaskOneQuestionId(condition.getCompetitionTaskOneQuestionId());
|
|
competitionTaskOneQuestion.setStudentAnswer(condition.getStudentAnswer());
|
|
competitionTaskOneQuestionService.updateTemplate(competitionTaskOneQuestion);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//更新分值
|
|
CompetitionTaskOneQuestionQuery competitionTaskOneQuestionQuery = new CompetitionTaskOneQuestionQuery();
|
|
competitionTaskOneQuestionQuery.setCompetitionId(condition.getCompetitionId());
|
|
competitionTaskOneQuestionQuery.setStudentsId(student.getStudentId());
|
|
|
|
BigDecimal totalScore = competitionTaskOneQuestionService.getTotalScoreByQuery(competitionTaskOneQuestionQuery);
|
|
|
|
CompetitionStudents competitionStudents = new CompetitionStudents();
|
|
competitionStudents.setCompetitionId(condition.getCompetitionId());
|
|
competitionStudents.setStudentsId(student.getStudentId());
|
|
competitionStudents.setCompetitionTaskOneFraction(totalScore);
|
|
competitionStudents.setCompetitionTaskOneFinishTime(((Integer)1).equals(condition.getBeSubmitted())?new Date():null);//判断是否是交卷
|
|
competitionStudentsService.updateTotalScore(competitionStudents);
|
|
|
|
return JsonResult.success();
|
|
}
|
|
|
|
//大赛任务二答卷
|
|
public JsonResult updateCT2QuestionAnswer(CompetitionTaskSecondQuestionStepQuery condition, Student student){
|
|
if(null == condition.getCompetitionTaskSecondQuestionStepId()){
|
|
return JsonResult.failMessage("参数丢失");
|
|
}
|
|
if(null == student){
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
}
|
|
|
|
CompetitionTaskSecondQuestionStep competitionTaskSecondQuestionStep = competitionTaskSecondQuestionStepService.queryById(condition.getCompetitionTaskSecondQuestionStepId());
|
|
CompetitionTaskSecondQuestion competitionTaskSecondQuestion = competitionTaskSecondQuestionService.queryById(competitionTaskSecondQuestionStep.getCompetitionTaskSecondQuestionId());
|
|
CompetitionStudents competitionStudents = competitionStudentsService.queryById(competitionTaskSecondQuestion.getCompetitionStudentsId());
|
|
Long competitionId = competitionStudents.getCompetitionId();
|
|
Competition competition = competitionService.getById(competitionId);
|
|
condition.setAddTime(TimeTool.getNowTime());
|
|
|
|
//对于交卷 加1分钟做缓冲
|
|
if(((Integer)1).equals(condition.getBeSubmitted()) && null != competition && competition.getCompetitionTaskSecondEndTime().getTime() < System.currentTimeMillis() - 60000 ){
|
|
return JsonResult.failMessage("提交失败,大赛任务二已结束");
|
|
}else if(!((Integer)1).equals(condition.getBeSubmitted()) && null != competitionStudents && competitionStudents.getCompetitionTaskSecondFinishTime() !=null && competitionStudents.getCompetitionTaskSecondFinishTime().getTime() < System.currentTimeMillis()){
|
|
return JsonResult.failMessage("提交失败,已交卷");
|
|
}else if(!((Integer)1).equals(condition.getBeSubmitted()) && null != competition && competition.getCompetitionTaskSecondEndTime().getTime() < System.currentTimeMillis()){
|
|
return JsonResult.failMessage("提交失败,大赛任务二已结束");
|
|
}
|
|
|
|
List<Future<Boolean>> results = new ArrayList<>();
|
|
results.add(pool.submit(new TaskCallableForCT2Q(condition, student,competition,competitionTaskSecondQuestion,competitionTaskSecondQuestionStep)));
|
|
|
|
return JsonResult.success();
|
|
}
|
|
|
|
//大赛任务二答卷 线程处理
|
|
private class TaskCallableForCT2Q implements Callable<Boolean> {
|
|
CompetitionTaskSecondQuestionStepQuery condition;
|
|
Student student;
|
|
Competition competition;
|
|
CompetitionTaskSecondQuestion competitionTaskSecondQuestion;
|
|
CompetitionTaskSecondQuestionStep competitionTaskSecondQuestionStep;
|
|
|
|
public TaskCallableForCT2Q(CompetitionTaskSecondQuestionStepQuery condition, Student student,Competition competition,CompetitionTaskSecondQuestion competitionTaskSecondQuestion,CompetitionTaskSecondQuestionStep competitionTaskSecondQuestionStep) {
|
|
this.condition = condition;
|
|
this.student = student;
|
|
this.competition = competition;
|
|
this.competitionTaskSecondQuestion = competitionTaskSecondQuestion;
|
|
this.competitionTaskSecondQuestionStep = competitionTaskSecondQuestionStep;
|
|
}
|
|
|
|
@Override
|
|
public Boolean call() {
|
|
CompetitionStudents competitionStudents = new CompetitionStudents();
|
|
competitionStudents.setCompetitionId(competition.getCompetitionId());
|
|
competitionStudents.setStudentsId(student.getStudentId());
|
|
competitionStudents.setCompetitionStudentsId(competitionTaskSecondQuestion.getCompetitionStudentsId());
|
|
List<CompetitionStudents> competitionStudentsList = competitionStudentsService.getValues(competitionStudents);
|
|
|
|
if(null != competitionStudentsList && competitionStudentsList.size()>0) {//判断答案和提交学员是否统一
|
|
if(TimeTool.getTime(condition.getAddTime()).getTime() <= competition.getCompetitionTaskSecondEndTime().getTime()){
|
|
|
|
BigDecimal score = BigDecimal.ZERO;
|
|
String competitionTaskSecondQuestionStepAnswer = competitionTaskSecondQuestionStep.getCompetitionTaskSecondQuestionStepAnswer();
|
|
|
|
List<String> studentAnswerList = new ArrayList<>();
|
|
try {
|
|
studentAnswerList = JSON.parseArray(condition.getStudentAnswer(), String.class);
|
|
} catch (Exception e) {
|
|
try {
|
|
studentAnswerList.add(JSONObject.parseObject(condition.getStudentAnswer(), String.class));
|
|
} catch (Exception e1) {}
|
|
}
|
|
|
|
//将学生答案替换到题目中
|
|
String studentAnswer = competitionTaskSecondQuestionStep.getCompetitionTaskSecondQuestionStepQuestion();
|
|
for(int i=0;null != studentAnswerList && i<studentAnswerList.size();i++){
|
|
String answer = StringUtils.isNotBlank(studentAnswerList.get(i))?studentAnswerList.get(i):"";
|
|
studentAnswer = studentAnswer.replaceFirst("___",answer.trim());
|
|
}
|
|
|
|
Double d = ToolUtils.judge(competitionTaskSecondQuestionStepAnswer,studentAnswer);
|
|
if(d == 100.0){
|
|
score = competitionTaskSecondQuestionStep.getCompetitionTaskSecondQuestionStepScore();
|
|
}
|
|
|
|
CompetitionTaskSecondQuestionStep ct2qStep = new CompetitionTaskSecondQuestionStep();
|
|
ct2qStep.setCompetitionTaskSecondQuestionStepId(condition.getCompetitionTaskSecondQuestionStepId());
|
|
ct2qStep.setStudentAnswer(condition.getStudentAnswer());
|
|
ct2qStep.setCompetitionTaskSecondQuestionStepGetScore(score);
|
|
competitionTaskSecondQuestionStepService.updateTemplate(ct2qStep);
|
|
}
|
|
}
|
|
|
|
//更新分值
|
|
CompetitionTaskSecondQuestionStepQuery competitionTaskSecondQuestionStepQuery = new CompetitionTaskSecondQuestionStepQuery();
|
|
competitionTaskSecondQuestionStepQuery.setCompetitionId(competition.getCompetitionId());
|
|
competitionTaskSecondQuestionStepQuery.setStudentsId(student.getStudentId());
|
|
|
|
BigDecimal totalScore = competitionTaskSecondQuestionStepService.getTotalScoreByQuery(competitionTaskSecondQuestionStepQuery);
|
|
|
|
competitionStudents = new CompetitionStudents();
|
|
competitionStudents.setCompetitionId(competition.getCompetitionId());
|
|
competitionStudents.setStudentsId(student.getStudentId());
|
|
competitionStudents.setCompetitionTaskSecondFraction(totalScore);
|
|
competitionStudents.setCompetitionTaskSecondFinishTime(((Integer)1).equals(condition.getBeSubmitted())?new Date():null);//判断是否是交卷
|
|
competitionStudentsService.updateTotalScore(competitionStudents);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
//考试任务一答卷
|
|
public JsonResult updateET1QuestionAnswer(ExamTaskOneQuestionQuery condition,Student student){
|
|
if(null == condition.getExamId()){
|
|
return JsonResult.failMessage("参数丢失");
|
|
}
|
|
if(null == student){
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
}
|
|
Exam exam = examService.queryById(condition.getExamId());
|
|
|
|
ExamStudents es = new ExamStudents();
|
|
es.setExamId(exam.getExamId());
|
|
es.setStudentsId(student.getStudentId());
|
|
es = examStudentsService.getValues(es).get(0);
|
|
|
|
//对于交卷 加1分钟做缓冲
|
|
if(((Integer)1).equals(condition.getBeSubmitted()) && null != exam && exam.getExamTaskOneEndTime().getTime() < System.currentTimeMillis() - 60000 ){
|
|
return JsonResult.failMessage("提交失败,考试任务一已结束");
|
|
}else if(!((Integer)1).equals(condition.getBeSubmitted()) && null != es && es.getExamTaskOneFinishTime() != null && es.getExamTaskOneFinishTime().getTime() < System.currentTimeMillis()){
|
|
return JsonResult.failMessage("提交失败,已交卷");
|
|
}else if(!((Integer)1).equals(condition.getBeSubmitted()) && null != exam && exam.getExamTaskOneEndTime().getTime() < System.currentTimeMillis()){
|
|
return JsonResult.failMessage("提交失败,考试任务一已结束");
|
|
}
|
|
|
|
ExamTaskOneQuestionQuery et1QQuery = new ExamTaskOneQuestionQuery();
|
|
et1QQuery.setExamId(condition.getExamId());
|
|
et1QQuery.setStudentsId(student.getStudentId());
|
|
List<ExamTaskOneQuestion> oldET1QuestionList = examTaskOneQuestionService.getValuesByQuery(et1QQuery);
|
|
Map<Long, List<ExamTaskOneQuestion>> groupByET1QId = null;
|
|
try{
|
|
groupByET1QId = oldET1QuestionList.stream().collect(Collectors.groupingBy(e -> e.getExamTaskOneQuestionId()));
|
|
}catch (Exception e){}
|
|
if(null == groupByET1QId){
|
|
return JsonResult.failMessage("数据有误,请联系管理员");
|
|
}
|
|
|
|
if(StringUtils.isNotBlank(condition.getET1QuestionMapJson())){
|
|
Map<String,JSONObject> eT1QuestionMap = new HashMap<>();
|
|
try {
|
|
eT1QuestionMap = (JSONObject.parseObject(condition.getET1QuestionMapJson(), HashMap.class));
|
|
} catch (Exception e) {}
|
|
List<ExamTaskOneQuestion>examTaskOneQuestionList = new ArrayList<>();
|
|
|
|
for(Map.Entry<String,JSONObject> entry:eT1QuestionMap.entrySet()){
|
|
|
|
ExamTaskOneQuestionQuery et1qq = JSONObject.toJavaObject(entry.getValue(),ExamTaskOneQuestionQuery.class);
|
|
|
|
if(null != entry.getValue() && StringUtils.isNotBlank(et1qq.getStudentAnswer()) && StringUtils.isNotBlank(et1qq.getAddTime())){
|
|
if(TimeTool.getTime(et1qq.getAddTime()).getTime() <= exam.getExamTaskOneEndTime().getTime()){
|
|
ExamTaskOneQuestion examTaskOneQuestion = new ExamTaskOneQuestion();
|
|
if(null == groupByET1QId.get(Long.parseLong(entry.getKey()))){//判断答案和提交学员是否统一
|
|
continue;
|
|
}
|
|
examTaskOneQuestion.setExamTaskOneQuestionId(et1qq.getExamTaskOneQuestionId());
|
|
examTaskOneQuestion.setStudentAnswer(resourcesQuestionService.answerFormat(groupByET1QId.get(Long.parseLong(entry.getKey())).get(0).getQuestionType(),et1qq.getStudentAnswer()));
|
|
examTaskOneQuestionList.add(examTaskOneQuestion);
|
|
}
|
|
}
|
|
}
|
|
if(examTaskOneQuestionList.size()>0){
|
|
examTaskOneQuestionService.updateBatchTemplate(examTaskOneQuestionList);
|
|
}
|
|
}else {
|
|
if(null != condition.getExamTaskOneQuestionId() && StringUtils.isNotBlank(condition.getStudentAnswer()) && StringUtils.isNotBlank(condition.getAddTime())){
|
|
if(TimeTool.getTime(condition.getAddTime()).getTime() <= exam.getExamTaskOneEndTime().getTime()){
|
|
ExamTaskOneQuestion examTaskOneQuestion = new ExamTaskOneQuestion();
|
|
if(null != groupByET1QId.get(condition.getExamTaskOneQuestionId())){//判断答案和提交学员是否统一
|
|
examTaskOneQuestion.setExamTaskOneQuestionId(condition.getExamTaskOneQuestionId());
|
|
examTaskOneQuestion.setStudentAnswer(condition.getStudentAnswer());
|
|
examTaskOneQuestionService.updateTemplate(examTaskOneQuestion);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//更新分值
|
|
ExamTaskOneQuestionQuery examTaskOneQuestionQuery = new ExamTaskOneQuestionQuery();
|
|
examTaskOneQuestionQuery.setExamId(condition.getExamId());
|
|
examTaskOneQuestionQuery.setStudentsId(student.getStudentId());
|
|
|
|
BigDecimal totalScore = examTaskOneQuestionService.getTotalScoreByQuery(examTaskOneQuestionQuery);
|
|
|
|
ExamStudents examStudents = new ExamStudents();
|
|
examStudents.setExamId(condition.getExamId());
|
|
examStudents.setStudentsId(student.getStudentId());
|
|
examStudents.setExamTaskOneFraction(totalScore);
|
|
examStudents.setExamTaskOneFinishTime(((Integer)1).equals(condition.getBeSubmitted())?new Date():null);//判断是否是交卷;
|
|
examStudentsService.updateTotalScore(examStudents);
|
|
|
|
return JsonResult.success();
|
|
}
|
|
|
|
//考试任务二答卷
|
|
public JsonResult updateET2QuestionAnswer(ExamTaskSecondQuestionStepQuery condition, Student student){
|
|
if(null == condition.getExamTaskSecondQuestionStepId()){
|
|
return JsonResult.failMessage("参数丢失");
|
|
}
|
|
if(null == student){
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
}
|
|
|
|
ExamTaskSecondQuestionStep examTaskSecondQuestionStep = examTaskSecondQuestionStepService.queryById(condition.getExamTaskSecondQuestionStepId());
|
|
ExamTaskSecondQuestion examTaskSecondQuestion = examTaskSecondQuestionService.queryById(examTaskSecondQuestionStep.getExamTaskSecondQuestionId());
|
|
ExamStudents examStudents = examStudentsService.queryById(examTaskSecondQuestion.getExamStudentsId());
|
|
Long examId = examStudents.getExamId();
|
|
Exam exam = examService.queryById(examId);
|
|
condition.setAddTime(TimeTool.getNowTime());
|
|
|
|
//对于交卷 加1分钟做缓冲
|
|
if(((Integer)1).equals(condition.getBeSubmitted()) && null != exam && exam.getExamTaskSecondEndTime().getTime() < System.currentTimeMillis() - 60000 ){
|
|
return JsonResult.failMessage("提交失败,考试任务二已结束");
|
|
}else if(!((Integer)1).equals(condition.getBeSubmitted()) && null != examStudents && examStudents.getExamTaskSecondFinishTime()!=null && examStudents.getExamTaskSecondFinishTime().getTime() < System.currentTimeMillis()){
|
|
return JsonResult.failMessage("提交失败,已交卷");
|
|
}else if(!((Integer)1).equals(condition.getBeSubmitted()) && null != exam && exam.getExamTaskSecondEndTime().getTime() < System.currentTimeMillis()){
|
|
return JsonResult.failMessage("提交失败,考试任务二已结束");
|
|
}
|
|
|
|
List<Future<Boolean>> results = new ArrayList<>();
|
|
results.add(pool.submit(new TaskCallableForET2Q(condition, student, exam, examTaskSecondQuestion,examTaskSecondQuestionStep)));
|
|
|
|
|
|
return JsonResult.success();
|
|
}
|
|
|
|
|
|
//考试任务二答卷 线程处理
|
|
private class TaskCallableForET2Q implements Callable<Boolean> {
|
|
ExamTaskSecondQuestionStepQuery condition;
|
|
Student student;
|
|
Exam exam;
|
|
ExamTaskSecondQuestion examTaskSecondQuestion;
|
|
ExamTaskSecondQuestionStep examTaskSecondQuestionStep;
|
|
|
|
public TaskCallableForET2Q(ExamTaskSecondQuestionStepQuery condition, Student student,Exam exam,ExamTaskSecondQuestion examTaskSecondQuestion,ExamTaskSecondQuestionStep examTaskSecondQuestionStep) {
|
|
this.condition = condition;
|
|
this.student = student;
|
|
this.exam = exam;
|
|
this.examTaskSecondQuestion = examTaskSecondQuestion;
|
|
this.examTaskSecondQuestionStep = examTaskSecondQuestionStep;
|
|
}
|
|
|
|
@Override
|
|
public Boolean call() {
|
|
ExamStudents examStudents = new ExamStudents();
|
|
examStudents.setExamId(exam.getExamId());
|
|
examStudents.setStudentsId(student.getStudentId());
|
|
examStudents.setExamStudentsId(examTaskSecondQuestion.getExamStudentsId());
|
|
List<ExamStudents> examStudentsList = examStudentsService.getValues(examStudents);
|
|
|
|
if(null != examStudentsList && examStudentsList.size()>0) {//判断答案和提交学员是否统一
|
|
if(TimeTool.getTime(condition.getAddTime()).getTime() <= exam.getExamTaskSecondEndTime().getTime()){
|
|
|
|
BigDecimal score = BigDecimal.ZERO;
|
|
String competitionTaskSecondQuestionStepAnswer = examTaskSecondQuestionStep.getExamTaskSecondQuestionStepAnswer();
|
|
|
|
List<String> studentAnswerList = new ArrayList<>();
|
|
try {
|
|
studentAnswerList = JSON.parseArray(condition.getStudentAnswer(), String.class);
|
|
} catch (Exception e) {
|
|
try {
|
|
studentAnswerList.add(JSONObject.parseObject(condition.getStudentAnswer(), String.class));
|
|
} catch (Exception e1) {}
|
|
}
|
|
|
|
//将学生答案替换到题目中
|
|
String studentAnswer = examTaskSecondQuestionStep.getExamTaskSecondQuestionStepQuestion();
|
|
for(int i=0;null != studentAnswerList && i<studentAnswerList.size();i++){
|
|
String answer = StringUtils.isNotBlank(studentAnswerList.get(i))?studentAnswerList.get(i):"";
|
|
studentAnswer = studentAnswer.replaceFirst("___",answer.trim());
|
|
}
|
|
|
|
Double d = ToolUtils.judge(competitionTaskSecondQuestionStepAnswer,studentAnswer);
|
|
if(d == 100.00){//TODO 暂定99%以上相似为正确
|
|
score = examTaskSecondQuestionStep.getExamTaskSecondQuestionStepScore();
|
|
}
|
|
|
|
ExamTaskSecondQuestionStep ct2qStep = new ExamTaskSecondQuestionStep();
|
|
ct2qStep.setExamTaskSecondQuestionStepId(condition.getExamTaskSecondQuestionStepId());
|
|
ct2qStep.setStudentAnswer(condition.getStudentAnswer());
|
|
ct2qStep.setExamTaskSecondQuestionStepGetScore(score);
|
|
examTaskSecondQuestionStepService.updateTemplate(ct2qStep);
|
|
}
|
|
}
|
|
|
|
//更新分值
|
|
ExamTaskSecondQuestionStepQuery examTaskSecondQuestionStepQuery = new ExamTaskSecondQuestionStepQuery();
|
|
examTaskSecondQuestionStepQuery.setExamId(exam.getExamId());
|
|
examTaskSecondQuestionStepQuery.setStudentsId(student.getStudentId());
|
|
|
|
BigDecimal totalScore = examTaskSecondQuestionStepService.getTotalScoreByQuery(examTaskSecondQuestionStepQuery);
|
|
|
|
examStudents = new ExamStudents();
|
|
examStudents.setExamId(exam.getExamId());
|
|
examStudents.setStudentsId(student.getStudentId());
|
|
examStudents.setExamTaskSecondFraction(totalScore);
|
|
examStudents.setExamTaskSecondFinishTime(((Integer)1).equals(condition.getBeSubmitted())?new Date():null);//判断是否是交卷;
|
|
examStudentsService.updateTotalScore(examStudents);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
//考试任务三答卷
|
|
public JsonResult updateET3QuestionAnswer(ExamTaskThreeQuestionStepQuery condition, Student student){
|
|
if(null == condition.getExamTaskThreeQuestionStepId()){
|
|
return JsonResult.failMessage("参数丢失");
|
|
}
|
|
if(null == student){
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
}
|
|
|
|
ExamTaskThreeQuestionStep examTaskThreeQuestionStep = examTaskThreeQuestionStepService.queryById(condition.getExamTaskThreeQuestionStepId());
|
|
ExamTaskThreeQuestion examTaskThreeQuestion = examTaskThreeQuestionService.queryById(examTaskThreeQuestionStep.getExamTaskThreeQuestionId());
|
|
ExamStudents examStudents = examStudentsService.queryById(examTaskThreeQuestion.getExamStudentsId());
|
|
Long examId = examStudents.getExamId();
|
|
Exam exam = examService.queryById(examId);
|
|
condition.setAddTime(TimeTool.getNowTime());
|
|
|
|
//对于交卷 加1分钟做缓冲
|
|
if(((Integer)1).equals(condition.getBeSubmitted()) && null != exam && exam.getExamTaskThreeEndTime().getTime() < System.currentTimeMillis() - 60000 ){
|
|
return JsonResult.failMessage("提交失败,考试任务三已结束");
|
|
}else if(!((Integer)1).equals(condition.getBeSubmitted()) && null != examStudents && examStudents.getExamTaskThreeFinishTime() !=null && examStudents.getExamTaskThreeFinishTime().getTime() < System.currentTimeMillis()){
|
|
return JsonResult.failMessage("提交失败,已交卷");
|
|
}else if(!((Integer)1).equals(condition.getBeSubmitted()) && null != exam && exam.getExamTaskThreeEndTime().getTime() < System.currentTimeMillis()){
|
|
return JsonResult.failMessage("提交失败,考试任务三已结束");
|
|
}
|
|
|
|
List<Future<Boolean>> results = new ArrayList<>();
|
|
results.add(pool.submit(new TaskCallableForET3Q(condition, student, exam, examTaskThreeQuestion,examTaskThreeQuestionStep)));
|
|
|
|
|
|
return JsonResult.success();
|
|
}
|
|
|
|
//考试任务三答卷 线程处理
|
|
private class TaskCallableForET3Q implements Callable<Boolean> {
|
|
ExamTaskThreeQuestionStepQuery condition;
|
|
Student student;
|
|
Exam exam;
|
|
ExamTaskThreeQuestion examTaskThreeQuestion;
|
|
ExamTaskThreeQuestionStep examTaskThreeQuestionStep;
|
|
|
|
public TaskCallableForET3Q(ExamTaskThreeQuestionStepQuery condition, Student student,Exam exam,ExamTaskThreeQuestion examTaskThreeQuestion,ExamTaskThreeQuestionStep examTaskThreeQuestionStep) {
|
|
this.condition = condition;
|
|
this.student = student;
|
|
this.exam = exam;
|
|
this.examTaskThreeQuestion = examTaskThreeQuestion;
|
|
this.examTaskThreeQuestionStep = examTaskThreeQuestionStep;
|
|
}
|
|
|
|
@Override
|
|
public Boolean call() {
|
|
ExamStudents examStudents = new ExamStudents();
|
|
examStudents.setExamId(exam.getExamId());
|
|
examStudents.setStudentsId(student.getStudentId());
|
|
examStudents.setExamStudentsId(examTaskThreeQuestion.getExamStudentsId());
|
|
List<ExamStudents> examStudentsList = examStudentsService.getValues(examStudents);
|
|
|
|
if(null != examStudentsList && examStudentsList.size()>0) {//判断答案和提交学员是否统一
|
|
if(TimeTool.getTime(condition.getAddTime()).getTime() <= exam.getExamTaskThreeEndTime().getTime()){
|
|
|
|
BigDecimal score = BigDecimal.ZERO;
|
|
String competitionTaskThreeQuestionStepAnswer = examTaskThreeQuestionStep.getExamTaskThreeQuestionStepAnswer();
|
|
|
|
|
|
List<String> studentAnswerList = new ArrayList<>();
|
|
try {
|
|
studentAnswerList = JSON.parseArray(condition.getStudentAnswer(), String.class);
|
|
} catch (Exception e) {
|
|
try {
|
|
studentAnswerList.add(JSONObject.parseObject(condition.getStudentAnswer(), String.class));
|
|
} catch (Exception e1) {}
|
|
}
|
|
|
|
//将学生答案替换到题目中
|
|
String studentAnswer = examTaskThreeQuestionStep.getExamTaskThreeQuestionStepQuestion();
|
|
for(int i=0;null != studentAnswerList && i<studentAnswerList.size();i++){
|
|
String answer = StringUtils.isNotBlank(studentAnswerList.get(i))?studentAnswerList.get(i):"";
|
|
studentAnswer = studentAnswer.replaceFirst("___",answer.trim());
|
|
}
|
|
|
|
Double d = ToolUtils.judge(competitionTaskThreeQuestionStepAnswer,studentAnswer);
|
|
if(d == 100.0){//TODO 暂定99%以上相似为正确
|
|
score = examTaskThreeQuestionStep.getExamTaskThreeQuestionStepScore();
|
|
}
|
|
|
|
ExamTaskThreeQuestionStep ct3qStep = new ExamTaskThreeQuestionStep();
|
|
ct3qStep.setExamTaskThreeQuestionStepId(condition.getExamTaskThreeQuestionStepId());
|
|
ct3qStep.setStudentAnswer(condition.getStudentAnswer());
|
|
ct3qStep.setExamTaskThreeQuestionStepGetScore(score);
|
|
examTaskThreeQuestionStepService.updateTemplate(ct3qStep);
|
|
}
|
|
}
|
|
|
|
//更新分值
|
|
ExamTaskThreeQuestionStepQuery examTaskThreeQuestionStepQuery = new ExamTaskThreeQuestionStepQuery();
|
|
examTaskThreeQuestionStepQuery.setExamId(exam.getExamId());
|
|
examTaskThreeQuestionStepQuery.setStudentsId(student.getStudentId());
|
|
|
|
BigDecimal totalScore = examTaskThreeQuestionStepService.getTotalScoreByQuery(examTaskThreeQuestionStepQuery);
|
|
|
|
examStudents = new ExamStudents();
|
|
examStudents.setExamId(exam.getExamId());
|
|
examStudents.setStudentsId(student.getStudentId());
|
|
examStudents.setExamTaskThreeFraction(totalScore);
|
|
examStudents.setExamTaskThreeFinishTime(((Integer)1).equals(condition.getBeSubmitted())?new Date():null);//判断是否是交卷;
|
|
examStudentsService.updateTotalScore(examStudents);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
//练习实训 答题记录
|
|
public JsonResult setStudentQuestionLog(StudentQuestionLogQuery studentQuestionLogQuery){
|
|
if(null == studentQuestionLogQuery.getResourcesQuestionId() && null == studentQuestionLogQuery.getResourcesCompetitionStepId() && null == studentQuestionLogQuery.getResourcesTrainingStepId()){
|
|
return JsonResult.failMessage("参数丢失");
|
|
}
|
|
if(null == studentQuestionLogQuery.getStudentId()){
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
}
|
|
studentQuestionLogQuery.setStudentQuestionLogAddTime(new Date());
|
|
|
|
|
|
List<Future<Boolean>> results = new ArrayList<>();
|
|
results.add(pool.submit(new TaskStudentQuestionLog(studentQuestionLogQuery)));
|
|
|
|
|
|
return JsonResult.success();
|
|
}
|
|
|
|
//答题记录 线程处理
|
|
private class TaskStudentQuestionLog implements Callable<Boolean> {
|
|
StudentQuestionLogQuery studentQuestionLogQuery;
|
|
|
|
public TaskStudentQuestionLog(StudentQuestionLogQuery studentQuestionLogQuery) {
|
|
this.studentQuestionLogQuery = studentQuestionLogQuery;
|
|
}
|
|
|
|
@Override
|
|
public Boolean call() {
|
|
|
|
studentQuestionLogQuery.setStudentQuestionLogId(null);
|
|
|
|
StudentQuestionLog studentQuestionLog = studentQuestionLogQuery.pojo();
|
|
List<StudentQuestionLog>studentQuestionLogList = studentQuestionLogService.getValues(studentQuestionLog);
|
|
if(null != studentQuestionLogList && studentQuestionLogList.size()>0){
|
|
studentQuestionLog = studentQuestionLogList.get(0);
|
|
}else {
|
|
studentQuestionLogService.insert(studentQuestionLog);
|
|
}
|
|
|
|
StudentQuestionLogAnswer studentQuestionLogAnswer = new StudentQuestionLogAnswer();
|
|
studentQuestionLogAnswer.setStudentQuestionLogId(studentQuestionLog.getStudentQuestionLogId());
|
|
studentQuestionLogAnswer.setStudentAnswer(studentQuestionLogQuery.getStudentAnswer());
|
|
studentQuestionLogAnswer.setAnswerAddTime(studentQuestionLogQuery.getStudentQuestionLogAddTime());
|
|
studentQuestionLogAnswerService.save(studentQuestionLogAnswer);
|
|
|
|
StudentQuestionLogInfo studentQuestionLogInfo = new StudentQuestionLogInfo();
|
|
studentQuestionLogInfo.setStudentQuestionLogId(studentQuestionLog.getStudentQuestionLogId());
|
|
studentQuestionLogInfo.setQuestionFraction(studentQuestionLogQuery.getQuestionFraction());
|
|
studentQuestionLogInfo.setStudentFraction(studentQuestionLogQuery.getStudentFraction());
|
|
studentQuestionLogInfo.setStudentQuestionLogAddTime(studentQuestionLogQuery.getStudentQuestionLogAddTime());
|
|
studentQuestionLogInfoService.save(studentQuestionLogInfo);
|
|
|
|
//错题数据
|
|
if(studentQuestionLogQuery.getQuestionFraction().equals(studentQuestionLogQuery.getStudentFraction())){
|
|
//查出错题,看看没有搞头
|
|
WrongQuestion wrongQuestion = studentQuestionLogQuery.pojo2WrongQuestion();
|
|
|
|
List<WrongQuestion>wrongQuestionList = wrongQuestionService.getValues(wrongQuestion);
|
|
if(null != wrongQuestionList && wrongQuestionList.size()>0){
|
|
//做对了,删除
|
|
wrongQuestionService.deleteWrongQuestion(wrongQuestionList.get(0).getStudentQuestionLogId().toString());
|
|
}
|
|
}else{
|
|
WrongQuestion wrongQuestion = studentQuestionLogQuery.pojo2WrongQuestion();
|
|
wrongQuestionService.save(wrongQuestion);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
//记录答辩数据
|
|
public JsonResult updateDefenceData(StudentDefenceLogQuery studentDefenceLogQuery,FileEntity fileEntity){
|
|
if(null == fileEntity){
|
|
return JsonResult.failMessage("请上传文件");
|
|
}
|
|
if(null == studentDefenceLogQuery.getResourcesTrainingId()){
|
|
return JsonResult.failMessage("参数丢失");
|
|
}
|
|
|
|
studentDefenceLogQuery.setStudentDefenceLogId(null);
|
|
|
|
StudentDefenceLog studentDefenceLog = studentDefenceLogQuery.pojo();
|
|
List<StudentDefenceLog>studentDefenceLogList = studentDefenceLogService.getValues(studentDefenceLog);
|
|
if(null != studentDefenceLogList && studentDefenceLogList.size()>0){
|
|
studentDefenceLog = studentDefenceLogList.get(0);
|
|
}else {
|
|
studentDefenceLogService.insert(studentDefenceLog);
|
|
}
|
|
|
|
StudentDefenceLogInfo studentDefenceLogInfo = new StudentDefenceLogInfo();
|
|
studentDefenceLogInfo.setStudentDefenceLogId(studentDefenceLog.getStudentDefenceLogId());
|
|
studentDefenceLogInfo.setStudentDefenceData(fileEntity.getUrl());
|
|
studentDefenceLogInfo.setStudentDefenceAddTime(new Date());
|
|
studentDefenceLogInfoService.save(studentDefenceLogInfo);
|
|
|
|
return JsonResult.success();
|
|
}
|
|
|
|
|
|
public JsonResult updateDefenceNote(StudentDefenceLogQuery studentDefenceLogQuery){
|
|
if(null == studentDefenceLogQuery.getResourcesTrainingId()){
|
|
return JsonResult.failMessage("参数丢失");
|
|
}
|
|
|
|
studentDefenceLogQuery.setStudentDefenceLogId(null);
|
|
|
|
StudentDefenceLog studentDefenceLog = studentDefenceLogQuery.pojo();
|
|
List<StudentDefenceLog>studentDefenceLogList = studentDefenceLogService.getValues(studentDefenceLog);
|
|
if(null != studentDefenceLogList && studentDefenceLogList.size()>0){
|
|
studentDefenceLog = studentDefenceLogList.get(0);
|
|
}else {
|
|
studentDefenceLogService.insert(studentDefenceLog);
|
|
}
|
|
|
|
StudentDefenceLogNote studentDefenceLogNote = new StudentDefenceLogNote();
|
|
studentDefenceLogNote.setStudentDefenceLogId(studentDefenceLog.getStudentDefenceLogId());
|
|
|
|
List<StudentDefenceLogNote>studentDefenceLogNoteList = studentDefenceLogNoteService.getValues(studentDefenceLogNote);
|
|
if(null != studentDefenceLogNoteList && studentDefenceLogNoteList.size()>0){
|
|
studentDefenceLogNote.setStudentDefenceLogNoteId(studentDefenceLogNoteList.get(0).getStudentDefenceLogNoteId());
|
|
studentDefenceLogNote.setNoteComment(studentDefenceLogQuery.getNoteComment());
|
|
studentDefenceLogNote.setNoteCommentOriginal(studentDefenceLogQuery.getNoteCommentOriginal());
|
|
studentDefenceLogNote.setNoteAddTime(new Date());
|
|
studentDefenceLogNoteService.updateTemplate(studentDefenceLogNote);
|
|
}else {
|
|
studentDefenceLogNote.setNoteComment(studentDefenceLogQuery.getNoteComment());
|
|
studentDefenceLogNote.setNoteCommentOriginal(studentDefenceLogQuery.getNoteCommentOriginal());
|
|
studentDefenceLogNote.setNoteAddTime(new Date());
|
|
studentDefenceLogNoteService.save(studentDefenceLogNote);
|
|
}
|
|
|
|
return JsonResult.success();
|
|
|
|
}
|
|
|
|
} |