|
@@ -0,0 +1,325 @@
|
|
|
+package com.qmth.themis.business.templete.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.qmth.themis.business.config.SystemConfig;
|
|
|
+import com.qmth.themis.business.constant.SystemConstant;
|
|
|
+import com.qmth.themis.business.dto.ExamStudentImportDto;
|
|
|
+import com.qmth.themis.business.dto.RoomCodeImportDto;
|
|
|
+import com.qmth.themis.business.entity.*;
|
|
|
+import com.qmth.themis.business.enums.RoleEnum;
|
|
|
+import com.qmth.themis.business.enums.TaskStatusEnum;
|
|
|
+import com.qmth.themis.business.service.*;
|
|
|
+import com.qmth.themis.business.templete.service.TempleteLogicService;
|
|
|
+import com.qmth.themis.business.util.OssUtil;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 导入导出模版处理逻辑 impl
|
|
|
+ * @Param:
|
|
|
+ * @return:
|
|
|
+ * @Author: wangliang
|
|
|
+ * @Date: 2020/7/31
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class TempleteLogicServiceImpl implements TempleteLogicService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TBTaskHistoryService tbTaskHistoryService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SystemConfig systemConfig;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ OssUtil ossUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TEExamStudentService teExamStudentService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TEStudentService teStudentService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TBExamInvigilateUserService tbExamInvigilateUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TBUserService tbUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TBUserRoleService tbUserRoleService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 考生导入逻辑
|
|
|
+ *
|
|
|
+ * @param finalList
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Map<String, Object> execImportExamStudentLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map) {
|
|
|
+ Long orgId = Long.parseLong(String.valueOf(map.get("orgId")));
|
|
|
+ Long examId = Long.parseLong(String.valueOf(map.get("examId")));
|
|
|
+ Long createId = Long.parseLong(String.valueOf(map.get("createId")));
|
|
|
+ List<String> txtList = (List<String>) map.get("txtList");
|
|
|
+ TBTaskHistory tbTaskHistory = (TBTaskHistory) map.get("tbTaskHistory");
|
|
|
+ String timeFormat = String.valueOf(map.get("timeFormat"));
|
|
|
+ List<TEExamStudent> teExamStudentList = new ArrayList<>();
|
|
|
+ List<TEStudent> teStudentList = new ArrayList<>();
|
|
|
+ List<TBExamInvigilateUser> tbExamInvigilateUserList = new ArrayList<>();
|
|
|
+ Gson gson = new Gson();
|
|
|
+ Set<String> roomCodeAndNameSet = new HashSet<>();
|
|
|
+ Map<String, TEExamActivity> teExamActivityMap = (Map<String, TEExamActivity>) map.get("teExamActivityMap");
|
|
|
+
|
|
|
+ //保存用户
|
|
|
+ for (int i = 0; i < finalList.size(); i++) {
|
|
|
+ LinkedMultiValueMap<Integer, Object> finalMap = finalList.get(i);
|
|
|
+ List<Object> examStudentImportDtoList = finalMap.get(i);
|
|
|
+ int min = 0;
|
|
|
+ int y = 0;
|
|
|
+ int max = SystemConstant.MAX_IMPORT_SIZE, size = examStudentImportDtoList.size();
|
|
|
+ if (max >= size) {
|
|
|
+ max = size;
|
|
|
+ }
|
|
|
+ while (max <= size) {
|
|
|
+ List subList = examStudentImportDtoList.subList(min, max);
|
|
|
+ for (; y < subList.size(); y++) {
|
|
|
+ ExamStudentImportDto examStudentImportDto = (ExamStudentImportDto) subList.get(y);
|
|
|
+ Map m = (Map) teExamActivityMap.get(examStudentImportDto.getExamActivityCode());
|
|
|
+ m = SystemConstant.timeTransform(m);
|
|
|
+ TEExamActivity teExamActivity = gson.fromJson(gson.toJson(m), TEExamActivity.class);
|
|
|
+ //先根据证件号+科目代码查询考生是否存在,存在则更新,不存在则插入
|
|
|
+ QueryWrapper<TEExamStudent> teExamStudentQueryWrapper = new QueryWrapper<>();
|
|
|
+ teExamStudentQueryWrapper.lambda().eq(TEExamStudent::getIdentity, examStudentImportDto.getIdentity()).eq(TEExamStudent::getCourseCode, examStudentImportDto.getCourseCode());
|
|
|
+ TEExamStudent teExamStudent = teExamStudentService.getOne(teExamStudentQueryWrapper);
|
|
|
+ //如果为空则插入考生数据,插入考生前先插入学生档案数据
|
|
|
+ if (Objects.isNull(teExamStudent)) {
|
|
|
+ QueryWrapper<TEStudent> teStudentQueryWrapper = new QueryWrapper<>();
|
|
|
+ teStudentQueryWrapper.lambda().eq(TEStudent::getIdentity, examStudentImportDto.getIdentity()).eq(TEStudent::getOrgId, orgId);
|
|
|
+ TEStudent teStudent = teStudentService.getOne(teStudentQueryWrapper);
|
|
|
+ if (Objects.isNull(teStudent)) {//如果学生数据为空则插入学生数据
|
|
|
+ //先插入学生档案数据
|
|
|
+ teStudent = new TEStudent(orgId, examStudentImportDto.getIdentity(), examStudentImportDto.getName(), createId);
|
|
|
+ teStudentService.save(teStudent);
|
|
|
+ teStudentList.add(teStudent);
|
|
|
+ }
|
|
|
+ teExamStudent = gson.fromJson(gson.toJson(examStudentImportDto), TEExamStudent.class);
|
|
|
+ teExamStudent.setExamId(examId);
|
|
|
+ teExamStudent.setExamActivityId(teExamActivity.getId());
|
|
|
+ teExamStudent.setStudentId(teStudent.getId());
|
|
|
+ teExamStudent.setCreateId(createId);
|
|
|
+ } else {
|
|
|
+ teExamStudent.setUpdateId(createId);
|
|
|
+ teExamStudent.setName(examStudentImportDto.getName());
|
|
|
+ teExamStudent.setCourseName(examStudentImportDto.getCourseName());
|
|
|
+ teExamStudent.setGrade(examStudentImportDto.getGrade());
|
|
|
+ teExamStudent.setClassNo(examStudentImportDto.getClassNo());
|
|
|
+ teExamStudent.setRoomCode(examStudentImportDto.getRoomCode());
|
|
|
+ teExamStudent.setRoomName(examStudentImportDto.getRoomName());
|
|
|
+ teExamStudent.setExamActivityId(teExamActivity.getId());
|
|
|
+ }
|
|
|
+ teExamStudentService.saveOrUpdate(teExamStudent);
|
|
|
+ roomCodeAndNameSet.add(teExamStudent.getRoomCode() + ":" + teExamStudent.getRoomName());
|
|
|
+ teExamStudentList.add(teExamStudent);
|
|
|
+ }
|
|
|
+ txtList = this.importProgress(max, min, size, txtList, tbTaskHistory, timeFormat);
|
|
|
+ map.put("min", min);
|
|
|
+ map.put("y", y);
|
|
|
+ if (max == size) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ min = max;
|
|
|
+ max += SystemConstant.MAX_IMPORT_SIZE;
|
|
|
+ if (max >= size) {
|
|
|
+ max = size;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //考场创建
|
|
|
+ if (Objects.nonNull(roomCodeAndNameSet) && roomCodeAndNameSet.size() > 0) {
|
|
|
+ Map<String, String> tbExamInvigilateUserMap = (Map<String, String>) map.get("tbExamInvigilateUserMap");
|
|
|
+ AtomicInteger count = new AtomicInteger(0);
|
|
|
+ roomCodeAndNameSet.forEach(s -> {
|
|
|
+ if (Objects.isNull(tbExamInvigilateUserMap) || (Objects.nonNull(tbExamInvigilateUserMap) && Objects.isNull(tbExamInvigilateUserMap.get(s)))) {
|
|
|
+ String[] strs = s.split(":");
|
|
|
+ TBExamInvigilateUser tbExamInvigilateUser = new TBExamInvigilateUser(orgId, strs[0], strs[1]);
|
|
|
+ tbExamInvigilateUserService.save(tbExamInvigilateUser);
|
|
|
+ tbExamInvigilateUserList.add(tbExamInvigilateUser);
|
|
|
+ count.getAndIncrement();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (count.get() > 0) {
|
|
|
+ txtList.add(DateUtil.format(new Date(), timeFormat) + "->创建了" + count + "条考场数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 考场导入逻辑
|
|
|
+ *
|
|
|
+ * @param finalList
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Map<String, Object> execImportRoomCodeLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map) {
|
|
|
+ Long orgId = null;
|
|
|
+ if (Objects.nonNull(map.get("orgId"))) {
|
|
|
+ orgId = Long.parseLong(String.valueOf(map.get("orgId")));
|
|
|
+ }
|
|
|
+ Long examId = null;
|
|
|
+ if (Objects.nonNull(map.get("examId"))) {
|
|
|
+ examId = Long.parseLong(String.valueOf(map.get("examId")));
|
|
|
+ }
|
|
|
+ Long createId = Long.parseLong(String.valueOf(map.get("createId")));
|
|
|
+ List<String> txtList = (List<String>) map.get("txtList");
|
|
|
+ TBTaskHistory tbTaskHistory = (TBTaskHistory) map.get("tbTaskHistory");
|
|
|
+ String timeFormat = String.valueOf(map.get("timeFormat"));
|
|
|
+ //保存用户
|
|
|
+ for (int i = 0; i < finalList.size(); i++) {
|
|
|
+ LinkedMultiValueMap<Integer, Object> finalMap = finalList.get(i);
|
|
|
+ List<Object> examStudentDtoImportList = finalMap.get(i);
|
|
|
+ int min = 0;
|
|
|
+ int y = 0;
|
|
|
+ int max = SystemConstant.MAX_IMPORT_SIZE, size = examStudentDtoImportList.size();
|
|
|
+ if (max >= size) {
|
|
|
+ max = size;
|
|
|
+ }
|
|
|
+ while (max <= size) {
|
|
|
+ List subList = examStudentDtoImportList.subList(min, max);
|
|
|
+ for (; y < subList.size(); y++) {
|
|
|
+ RoomCodeImportDto roomCodeImportDto = (RoomCodeImportDto) subList.get(y);
|
|
|
+ dataVerify(roomCodeImportDto.getTeacher1(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), orgId, createId);
|
|
|
+ dataVerify(roomCodeImportDto.getTeacher2(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), orgId, createId);
|
|
|
+ dataVerify(roomCodeImportDto.getTeacher3(), roomCodeImportDto.getRoomCode(), roomCodeImportDto.getRoomName(), orgId, createId);
|
|
|
+ }
|
|
|
+ txtList = this.importProgress(max, min, size, txtList, tbTaskHistory, timeFormat);
|
|
|
+ if (max == size) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ min = max;
|
|
|
+ max += SystemConstant.MAX_IMPORT_SIZE;
|
|
|
+ if (max >= size) {
|
|
|
+ max = size;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 考场导出逻辑
|
|
|
+ *
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Map<String, Object> execExportRoomCodeLogic(Map<String, Object> map) {
|
|
|
+ List<String> txtList = (List<String>) map.get("txtList");
|
|
|
+ TBTaskHistory tbTaskHistory = (TBTaskHistory) map.get("tbTaskHistory");
|
|
|
+ Integer max = Integer.parseInt(String.valueOf(map.get("max")));
|
|
|
+ Integer min = Integer.parseInt(String.valueOf(map.get("min")));
|
|
|
+ Integer size = Integer.parseInt(String.valueOf(map.get("size")));
|
|
|
+ String timeFormat = String.valueOf(map.get("timeFormat"));
|
|
|
+ this.exportProgress(max, min, size, txtList, tbTaskHistory, timeFormat);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询监考帐号是否存在
|
|
|
+ *
|
|
|
+ * @param userName
|
|
|
+ * @param roomCode
|
|
|
+ * @param roomName
|
|
|
+ * @param orgId
|
|
|
+ * @param createId
|
|
|
+ */
|
|
|
+ public void dataVerify(String userName, String roomCode, String roomName, Long orgId, Long createId) {
|
|
|
+ if (Objects.nonNull(userName)) {
|
|
|
+ //先查询监考帐号是否存在
|
|
|
+ QueryWrapper<TBUser> tbUserQueryWrapper = new QueryWrapper<>();
|
|
|
+ tbUserQueryWrapper.lambda().eq(TBUser::getLoginName, userName).eq(TBUser::getOrgId, orgId);
|
|
|
+ TBUser tbUser = tbUserService.getOne(tbUserQueryWrapper);
|
|
|
+ if (Objects.isNull(tbUser)) {
|
|
|
+ //新增用户
|
|
|
+ tbUser = new TBUser(orgId, userName, userName, createId);
|
|
|
+ tbUserService.save(tbUser);
|
|
|
+
|
|
|
+ TBUserRole tbUserRole = new TBUserRole(tbUser.getId(), RoleEnum.INVIGILATE.name());
|
|
|
+ tbUserRoleService.save(tbUserRole);
|
|
|
+ }
|
|
|
+ //新增考场
|
|
|
+ TBExamInvigilateUser tbExamInvigilateUser = new TBExamInvigilateUser(orgId, tbUser.getId(), roomCode, roomName);
|
|
|
+ tbExamInvigilateUserService.save(tbExamInvigilateUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入换算进度
|
|
|
+ *
|
|
|
+ * @param max
|
|
|
+ * @param min
|
|
|
+ * @param size
|
|
|
+ * @param txtList
|
|
|
+ * @param tbTaskHistory
|
|
|
+ * @param timeFormat
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> importProgress(int max, int min, int size, List<String> txtList, TBTaskHistory tbTaskHistory, String timeFormat) {
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(100);
|
|
|
+ BigDecimal progress = new BigDecimal(Double.valueOf(new BigDecimal(max).divide(new BigDecimal(size), 2, BigDecimal.ROUND_HALF_UP).multiply(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if (progress.intValue() == 100) {
|
|
|
+ tbTaskHistory.setStatus(TaskStatusEnum.finish);
|
|
|
+ tbTaskHistory.setSummary("共处理了" + size + "条数据");
|
|
|
+ tbTaskHistory.setFinishTime(new Date());
|
|
|
+ txtList.add(DateUtil.format(new Date(), timeFormat) + "->数据处理完毕," + tbTaskHistory.getSummary());
|
|
|
+ } else {
|
|
|
+ tbTaskHistory.setStatus(TaskStatusEnum.running);
|
|
|
+ tbTaskHistory.setSummary("正在处理第" + min + "条至" + max + "条数据");
|
|
|
+ txtList.add(DateUtil.format(new Date(), timeFormat) + "->数据处理中," + tbTaskHistory.getSummary());
|
|
|
+ }
|
|
|
+ tbTaskHistory.setProgress(progress.doubleValue());
|
|
|
+ tbTaskHistoryService.updateById(tbTaskHistory);
|
|
|
+ return txtList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出换算进度
|
|
|
+ *
|
|
|
+ * @param max
|
|
|
+ * @param min
|
|
|
+ * @param size
|
|
|
+ * @param txtList
|
|
|
+ * @param tbTaskHistory
|
|
|
+ * @param timeFormat
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> exportProgress(int max, int min, int size, List<String> txtList, TBTaskHistory tbTaskHistory, String timeFormat) {
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(100);
|
|
|
+ BigDecimal progress = new BigDecimal(Double.valueOf(new BigDecimal(max).divide(new BigDecimal(size), 2, BigDecimal.ROUND_HALF_UP).multiply(bigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue())).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if (progress.intValue() == 100) {
|
|
|
+ tbTaskHistory.setStatus(TaskStatusEnum.finish);
|
|
|
+ tbTaskHistory.setSummary("共导出了" + size + "条数据");
|
|
|
+ tbTaskHistory.setFinishTime(new Date());
|
|
|
+ txtList.add(DateUtil.format(new Date(), timeFormat) + "->数据导出完毕," + tbTaskHistory.getSummary());
|
|
|
+ } else {
|
|
|
+ tbTaskHistory.setStatus(TaskStatusEnum.running);
|
|
|
+ tbTaskHistory.setSummary("正在导出第" + min + "条至" + max + "条数据");
|
|
|
+ txtList.add(DateUtil.format(new Date(), timeFormat) + "->数据导出中," + tbTaskHistory.getSummary());
|
|
|
+ }
|
|
|
+ tbTaskHistory.setProgress(progress.doubleValue());
|
|
|
+ tbTaskHistoryService.updateById(tbTaskHistory);
|
|
|
+ return txtList;
|
|
|
+ }
|
|
|
+}
|