|
@@ -12,22 +12,27 @@ import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.GradeBatchStudentDto;
|
|
|
import com.qmth.distributed.print.business.bean.params.analyze.GradeBatchParam;
|
|
|
import com.qmth.distributed.print.business.bean.result.analyze.GradeBatchResult;
|
|
|
+import com.qmth.distributed.print.business.entity.ExamTask;
|
|
|
import com.qmth.distributed.print.business.entity.GradeBatch;
|
|
|
import com.qmth.distributed.print.business.entity.GradeBatchPaper;
|
|
|
import com.qmth.distributed.print.business.entity.GradeBatchStudent;
|
|
|
import com.qmth.distributed.print.business.mapper.ExamStudentMapper;
|
|
|
import com.qmth.distributed.print.business.mapper.GradeBatchMapper;
|
|
|
+import com.qmth.distributed.print.business.service.ExamTaskService;
|
|
|
import com.qmth.distributed.print.business.service.GradeBatchPaperService;
|
|
|
import com.qmth.distributed.print.business.service.GradeBatchService;
|
|
|
import com.qmth.distributed.print.business.service.GradeBatchStudentService;
|
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SpringContextHolder;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
+import com.qmth.teachcloud.common.entity.SysOrg;
|
|
|
+import com.qmth.teachcloud.common.entity.SysRole;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
-import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
-import com.qmth.teachcloud.common.enums.GradeAnalyzePaperStatusEnum;
|
|
|
-import com.qmth.teachcloud.common.enums.TaskResultEnum;
|
|
|
-import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
|
+import com.qmth.teachcloud.common.entity.SysUserRole;
|
|
|
+import com.qmth.teachcloud.common.enums.*;
|
|
|
+import com.qmth.teachcloud.common.service.SysRoleService;
|
|
|
+import com.qmth.teachcloud.common.service.SysUserRoleService;
|
|
|
+import com.qmth.teachcloud.common.service.SysUserService;
|
|
|
import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
|
import com.qmth.teachcloud.common.util.ExcelUtil;
|
|
|
import com.qmth.teachcloud.common.util.FileStoreUtil;
|
|
@@ -75,13 +80,25 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
|
|
|
@Resource
|
|
|
TeachcloudCommonService teachcloudCommonService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ SysUserService sysUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SysRoleService sysRoleService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SysUserRoleService sysUserRoleService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ ExamTaskService examTaskService;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<GradeBatchResult> gradeBatchPage(String batchName, int pageNumber, int pageSize, SysUser requestUser) {
|
|
|
batchName = SystemConstant.translateSpecificSign(batchName);
|
|
|
IPage<GradeBatchResult> page = this.baseMapper.findGradeBatchPage(new Page<>(pageNumber, pageSize), batchName, requestUser.getSchoolId());
|
|
|
for (GradeBatchResult record : page.getRecords()) {
|
|
|
String txtPath = record.getReportFilePath();
|
|
|
- if (SystemConstant.strNotNull(txtPath)){
|
|
|
+ if (SystemConstant.strNotNull(txtPath)) {
|
|
|
record.setReportFilePath(teachcloudCommonService.filePreview(txtPath));
|
|
|
}
|
|
|
}
|
|
@@ -96,7 +113,7 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
|
|
|
Long id = gradeBatchParam.getId();
|
|
|
String batchName = gradeBatchParam.getBatchName();
|
|
|
Long batchTime = gradeBatchParam.getBatchTime();
|
|
|
- if (!SystemConstant.longNotNull(batchTime)){
|
|
|
+ if (!SystemConstant.longNotNull(batchTime)) {
|
|
|
batchTime = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
@@ -227,6 +244,7 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
|
|
|
@Override
|
|
|
public void uploadFile(Long batchId, MultipartFile file) throws IOException, NoSuchFieldException {
|
|
|
List<GradeBatchStudentDto> list = new ArrayList<>();
|
|
|
+ Map<String, String> teacherMap = new HashMap<>();
|
|
|
List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(file.getInputStream(), Lists.newArrayList(GradeBatchStudentDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
|
|
|
List<ExcelError> excelErrorTemp = new ArrayList<>();
|
|
|
// 只允许导入一个sheet
|
|
@@ -234,7 +252,6 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
|
|
|
throw ExceptionResultEnum.ERROR.exception("excel中只允许有一个sheet");
|
|
|
}
|
|
|
|
|
|
- Map<String, String> teacherMap = new HashMap<>();
|
|
|
for (int i = 0; i < finalExcelList.size(); i++) {
|
|
|
LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
|
|
|
List<Object> gradeBatchStudentTempList = excelMap.get(i);
|
|
@@ -269,7 +286,7 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
|
|
|
if (StringUtils.isBlank(teacherNumber)) {
|
|
|
excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[任课老师工号]必填"));
|
|
|
}
|
|
|
- if(teacherMap.containsKey(teacherNumber) && !teacherName.equals(teacherMap.get(teacherNumber))){
|
|
|
+ if (teacherMap.containsKey(teacherNumber) && !teacherName.equals(teacherMap.get(teacherNumber))) {
|
|
|
excelErrorTemp.add(new ExcelError(y + 1, "excel中同一个任课老师工号有多个姓名"));
|
|
|
}
|
|
|
|
|
@@ -290,9 +307,9 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void createTxt(GradeBatch gradeBatch,String exception) {
|
|
|
+ public void createTxt(GradeBatch gradeBatch, String exception) {
|
|
|
final String TXT_PREFIX = ".txt";
|
|
|
- if (Objects.isNull(gradeBatch)){
|
|
|
+ if (Objects.isNull(gradeBatch)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("批次不存在");
|
|
|
}
|
|
|
FileStoreUtil fileStoreUtil = SpringContextHolder.getBean(FileStoreUtil.class);
|
|
@@ -301,7 +318,7 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
|
|
|
InputStream inputStream = null;
|
|
|
try {
|
|
|
// 有异常才创建txt文件
|
|
|
- if (SystemConstant.strNotNull(exception)){
|
|
|
+ if (SystemConstant.strNotNull(exception)) {
|
|
|
boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
LocalDateTime nowTime = LocalDateTime.now();
|
|
|
StringJoiner stringJoiner = new StringJoiner("");
|
|
@@ -383,5 +400,66 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
gradeBatchStudentService.saveBatch(gradeBatchStudents);
|
|
|
+
|
|
|
+ GradeBatch gradeBatch = this.getById(batchId);
|
|
|
+
|
|
|
+ if (gradeBatch == null) {
|
|
|
+ throw ExceptionResultEnum.SUCCESS.exception("未找到批次信息");
|
|
|
+ }
|
|
|
+ Long schoolId = gradeBatch.getSchoolId();
|
|
|
+
|
|
|
+ QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysRoleQueryWrapper.lambda().eq(SysRole::getType, RoleTypeEnum.TEACHER).eq(SysRole::getEnable, true);
|
|
|
+ List<SysRole> sysRoleList = sysRoleService.list(sysRoleQueryWrapper);
|
|
|
+ if (sysRoleList.isEmpty()) {
|
|
|
+ throw ExceptionResultEnum.SUCCESS.exception("未找到任课老师角色,请联系管理员");
|
|
|
+ }
|
|
|
+ Map<String, List<GradeBatchStudentDto>> listMap = list.stream().collect(Collectors.groupingBy(m -> m.getTeacherNumber() + "##" + m.getTeacherName()));
|
|
|
+ for (Map.Entry<String, List<GradeBatchStudentDto>> entry : listMap.entrySet()) {
|
|
|
+ String[] key = entry.getKey().split("##");
|
|
|
+ List<GradeBatchStudentDto> dtoList = entry.getValue();
|
|
|
+ List<SysUser> sysUserList = sysUserService.findBySchoolIdAndCode(schoolId, key[0]);
|
|
|
+ if (!sysUserList.isEmpty() && sysUserList.size() > 1) {
|
|
|
+ throw ExceptionResultEnum.SUCCESS.exception(key[0] + "找到多条用户记录");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> orgIds = dtoList.stream().map(m -> m.getCourseCode() + "##" + m.getPaperNumber()).distinct().map(m -> {
|
|
|
+ String[] strings = m.split("##");
|
|
|
+ ExamTask examTask = examTaskService.getByCourseCodeAndPaperNumber(schoolId, strings[0], strings[1]);
|
|
|
+ SysOrg sysOrg = gradeBatchPaperService.findTeachCollegeByOrgId(examTask.getTeachingRoomId());
|
|
|
+ return sysOrg.getId();
|
|
|
+ }).distinct().collect(Collectors.toList());
|
|
|
+ if (orgIds.size() != 1) {
|
|
|
+ throw ExceptionResultEnum.SUCCESS.exception("任课老师" + key[0] + "对应课程不能属于不同学院");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUser sysUser;
|
|
|
+ if (sysUserList.isEmpty()) {
|
|
|
+ //新增
|
|
|
+ sysUser = new SysUser(schoolId, key[0], key[1], null, true);
|
|
|
+ sysUser.setCode(key[0]);
|
|
|
+ sysUser.setOrgId(orgIds.get(0));
|
|
|
+ sysUserService.save(sysUser);
|
|
|
+ } else {
|
|
|
+ //修改
|
|
|
+ sysUser = sysUserList.get(0);
|
|
|
+ sysUser.setRealName(key[1]);
|
|
|
+ sysUser.setEnable(true);
|
|
|
+ sysUser.setOrgId(orgIds.get(0));
|
|
|
+ sysUserService.updateById(sysUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绑定角色
|
|
|
+ List<SysRole> sysUserRoles = sysUserRoleService.listRoleByUserId(sysUser.getId());
|
|
|
+ long count = sysUserRoles.stream().filter(m -> m.getId().longValue() == sysRoleList.get(0).getId().longValue()).count();
|
|
|
+ if (count == 0) {
|
|
|
+ SysUserRole sysUserRole = new SysUserRole();
|
|
|
+ sysUserRole.setId(SystemConstant.getDbUuid());
|
|
|
+ sysUserRole.setUserId(sysUser.getId());
|
|
|
+ sysUserRole.setRoleId(sysRoleList.get(0).getId());
|
|
|
+ sysUserRole.setEnable(true);
|
|
|
+ sysUserRoleService.save(sysUserRole);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|