123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768 |
- package cn.com.qmth.scancentral.service.impl;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.nio.charset.Charset;
- import java.util.*;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.LinkedBlockingQueue;
- import java.util.concurrent.ThreadPoolExecutor;
- import java.util.concurrent.TimeUnit;
- import org.apache.commons.collections4.CollectionUtils;
- import org.apache.commons.io.IOUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
- import com.linuxense.javadbf.DBFDataType;
- import com.linuxense.javadbf.DBFField;
- import com.linuxense.javadbf.DBFWriter;
- import com.qmth.boot.core.exception.ParameterException;
- import com.qmth.boot.core.exception.StatusException;
- import com.qmth.boot.core.fss.store.FileStore;
- import com.qmth.boot.tools.uuid.FastUUID;
- import cn.com.qmth.scancentral.bean.ImportSubjectDomain;
- import cn.com.qmth.scancentral.consumer.AnswerDataExportConsumer;
- import cn.com.qmth.scancentral.consumer.SliceDataExportConsumer;
- import cn.com.qmth.scancentral.dao.SubjectDao;
- import cn.com.qmth.scancentral.entity.ExamEntity;
- import cn.com.qmth.scancentral.entity.MarkSiteEntity;
- import cn.com.qmth.scancentral.entity.SubjectEntity;
- import cn.com.qmth.scancentral.enums.AsyncTaskStatus;
- import cn.com.qmth.scancentral.enums.ExamStatus;
- import cn.com.qmth.scancentral.enums.ScanStatus;
- import cn.com.qmth.scancentral.service.AsyncTaskService;
- import cn.com.qmth.scancentral.service.BatchPaperService;
- import cn.com.qmth.scancentral.service.ExamService;
- import cn.com.qmth.scancentral.service.FileService;
- import cn.com.qmth.scancentral.service.MarkSiteService;
- import cn.com.qmth.scancentral.service.OmrGroupService;
- import cn.com.qmth.scancentral.service.StudentService;
- import cn.com.qmth.scancentral.service.SubjectService;
- import cn.com.qmth.scancentral.support.SpringContextHolder;
- import cn.com.qmth.scancentral.util.Calculator;
- import cn.com.qmth.scancentral.util.DateUtil;
- import cn.com.qmth.scancentral.util.FileUtil;
- import cn.com.qmth.scancentral.vo.ExportCetMarkingQueryVo;
- import cn.com.qmth.scancentral.vo.ExportCetVo;
- import cn.com.qmth.scancentral.vo.OmrGroupVo;
- import cn.com.qmth.scancentral.vo.UpdateTimeVo;
- import cn.com.qmth.scancentral.vo.omr.OmrSubjectVo;
- import cn.com.qmth.scancentral.vo.subject.DataExportTaskVo;
- import cn.com.qmth.scancentral.vo.subject.ScanProgressVo;
- import cn.com.qmth.scancentral.vo.subject.SubjectBreachVo;
- import cn.com.qmth.scancentral.vo.subject.SubjectCustStatusVo;
- import cn.com.qmth.scancentral.vo.subject.SubjectScanProgressVo;
- import cn.com.qmth.scancentral.vo.subject.TaskIdVo;
- @Service
- public class SubjectServiceImpl extends MppServiceImpl<SubjectDao, SubjectEntity> implements SubjectService {
- private static final Logger log = LoggerFactory.getLogger(SubjectService.class);
- private static ExecutorService exec;
- @Autowired
- private ExamService examService;
- @Autowired
- private StudentService studentService;
- @Autowired
- private FileService fileService;
- @Autowired
- private FileStore fileStore;
- @Autowired
- private BatchPaperService batchPaperService;
- @Autowired
- private AsyncTaskService asyncTaskService;
- @Autowired
- private MarkSiteService markSiteService;
- @Autowired
- private OmrGroupService omrGroupService;
- static {
- int threadCount = 5;
- exec = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.SECONDS,
- new LinkedBlockingQueue<>(threadCount * 2), r -> {
- Thread t = new Thread(r);
- return t;
- }, (r, executor) -> {
- if (!executor.isShutdown()) {
- try {
- executor.getQueue().put(r);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- });
- }
- @Override
- public List<SubjectEntity> listByExamId(Long examId) {
- QueryWrapper<SubjectEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(SubjectEntity::getExamId, examId);
- queryWrapper.lambda().orderByAsc(SubjectEntity::getCode);
- return this.list(queryWrapper);
- }
- @Override
- public SubjectEntity findByExamIdAndCode(Long examId, String code) {
- QueryWrapper<SubjectEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(SubjectEntity::getExamId, examId);
- queryWrapper.lambda().eq(SubjectEntity::getCode, code);
- return this.getOne(queryWrapper);
- }
- @Override
- public int countByExamId(Long examId) {
- QueryWrapper<SubjectEntity> wrapper = new QueryWrapper<>();
- LambdaQueryWrapper<SubjectEntity> lw = wrapper.lambda();
- lw.eq(SubjectEntity::getExamId, examId);
- return this.count(wrapper);
- }
- @Transactional
- @Override
- public int importSubject(List<ImportSubjectDomain> subjects) {
- Map<Long, Set<String>> map = new HashMap<Long, Set<String>>();
- List<SubjectEntity> list = this.list();
- for (SubjectEntity subjectEntity : list) {
- Set<String> set = map.get(subjectEntity.getExamId());
- if (set == null) {
- set = new HashSet<String>();
- }
- set.add(subjectEntity.getCode());
- map.put(subjectEntity.getExamId(), set);
- }
- List<SubjectEntity> saveList = new ArrayList<SubjectEntity>();
- for (ImportSubjectDomain importSubjectDomain : subjects) {
- Set<String> set = map.get(importSubjectDomain.getExamId());
- if (set != null) {
- if (!set.contains(importSubjectDomain.getSubjectCode())) {
- SubjectEntity subjectEntity = new SubjectEntity(importSubjectDomain.getExamId(),
- importSubjectDomain.getSubjectCode(), importSubjectDomain.getSubjectName());
- set.add(importSubjectDomain.getSubjectCode());
- saveList.add(subjectEntity);
- }
- } else {
- set = new HashSet<String>();
- SubjectEntity subjectEntity = new SubjectEntity(importSubjectDomain.getExamId(),
- importSubjectDomain.getSubjectCode(), importSubjectDomain.getSubjectName());
- set.add(importSubjectDomain.getSubjectCode());
- saveList.add(subjectEntity);
- }
- map.put(importSubjectDomain.getExamId(), set);
- }
- this.saveOrUpdateBatchByMultiId(saveList);
- return saveList.size();
- }
- @Override
- public ScanProgressVo scanProgress(Long examId, String subjectCode) {
- ScanProgressVo ret = new ScanProgressVo();
- // List<SubjectScanProgressVo> subjects =
- // studentService.scanProgress(examId, subjectCode);
- List<SubjectScanProgressVo> subjects = new ArrayList<>();
- if (StringUtils.isNotBlank(subjectCode)) {
- SubjectEntity subject = this.findByExamIdAndCode(examId, subjectCode);
- SubjectScanProgressVo vo = new SubjectScanProgressVo();
- vo.setSubjectCode(subject.getCode());
- vo.setSubjectName(subject.getName());
- vo.setUnexistCount(studentService.getUnscannedCountByExamAndSubject(examId, subject.getCode()));
- vo.setStudentCount(studentService.countByExamIdAndSubjectCode(examId, subject.getCode()));
- subjects.add(vo);
- } else {
- List<SubjectEntity> subjectList = this.listByExamId(examId);
- for (SubjectEntity subject : subjectList) {
- SubjectScanProgressVo vo = new SubjectScanProgressVo();
- vo.setSubjectCode(subject.getCode());
- vo.setSubjectName(subject.getName());
- vo.setUnexistCount(studentService.getUnscannedCountByExamAndSubject(examId, subject.getCode()));
- vo.setStudentCount(studentService.countByExamIdAndSubjectCode(examId, subject.getCode()));
- subjects.add(vo);
- }
- }
- ret.setSubjects(subjects);
- Calendar now = Calendar.getInstance();
- long endTime = now.getTimeInMillis();
- now.add(Calendar.HOUR_OF_DAY, -1);
- long startTime = now.getTimeInMillis();
- Integer inTimeScannedCount = batchPaperService.getScanStudentCount(examId, null, startTime, endTime);
- if (CollectionUtils.isNotEmpty(subjects)) {
- for (SubjectScanProgressVo vo : subjects) {
- vo.setScannedCount(vo.getStudentCount() - vo.getUnexistCount());
- vo.setProgress(Calculator.percentage(vo.getScannedCount(), vo.getStudentCount(), 2));
- if (inTimeScannedCount == null || inTimeScannedCount == 0) {
- vo.setEstimation("-");
- } else {
- double speed = Calculator.divide(endTime - startTime, inTimeScannedCount, 6);
- double es = Calculator.divide(Calculator.multiply(speed, vo.getUnexistCount()), 3600000, 2);
- vo.setEstimation(es + "h");
- }
- }
- }
- ret.setTotal(new SubjectScanProgressVo());
- ret.getTotal().setStudentCount(studentService.getCountByExam(examId));
- ret.getTotal().setScannedCount(studentService.getCountByExamAndScanStatus(examId, ScanStatus.SCANNED));
- ret.getTotal().setUnexistCount(ret.getTotal().getStudentCount() - ret.getTotal().getScannedCount());
- ret.getTotal().setProgress(
- Calculator.percentage(ret.getTotal().getScannedCount(), ret.getTotal().getStudentCount(), 2));
- if (inTimeScannedCount == null || inTimeScannedCount == 0) {
- ret.getTotal().setEstimation("-");
- } else {
- double speed = Calculator.divide(endTime - startTime, inTimeScannedCount, 6);
- double es = Calculator.divide(Calculator.multiply(speed, ret.getTotal().getUnexistCount()), 3600000, 2);
- ret.getTotal().setEstimation(es + "h");
- }
- return ret;
- }
- @Override
- public List<SubjectBreachVo> breachList(Long examId) {
- List<SubjectBreachVo> ret = new ArrayList<>();
- List<SubjectEntity> subjects = listByExamId(examId);
- if (CollectionUtils.isNotEmpty(subjects)) {
- for (SubjectEntity e : subjects) {
- SubjectBreachVo vo = new SubjectBreachVo();
- ret.add(vo);
- vo.setSubjectCode(e.getCode());
- vo.setSubjectName(e.getName());
- String url = fileService.getBreachInfoUri(examId, e.getCode());
- try {
- if (fileStore.exist(url)) {
- vo.setBreachCount(Integer.valueOf(FileUtil.readFileContent(fileStore.read(url)).trim()));
- } else {
- vo.setBreachCount(0);
- }
- } catch (Exception e1) {
- throw new RuntimeException("文件访问异常", e1);
- }
- }
- }
- return ret;
- }
- @Override
- public List<SubjectCustStatusVo> custStatusList(Long examId) {
- List<SubjectCustStatusVo> ret = new ArrayList<>();
- List<SubjectEntity> subjects = listByExamId(examId);
- if (CollectionUtils.isNotEmpty(subjects)) {
- for (SubjectEntity e : subjects) {
- SubjectCustStatusVo vo = new SubjectCustStatusVo();
- ret.add(vo);
- vo.setSubjectCode(e.getCode());
- vo.setSubjectName(e.getName());
- String url = fileService.getCustStatusInfoUri(examId, e.getCode());
- try {
- if (fileStore.exist(url)) {
- vo.setCustStatusCount(Integer.valueOf(FileUtil.readFileContent(fileStore.read(url)).trim()));
- } else {
- vo.setCustStatusCount(0);
- }
- } catch (Exception e1) {
- throw new RuntimeException("文件访问异常", e1);
- }
- }
- }
- return ret;
- }
- @Override
- public TaskIdVo answerDataExport(Long examId, String subjectCode) {
- ExportCetMarkingQueryVo req = new ExportCetMarkingQueryVo();
- req.setExamId(examId);
- req.setSubjectCode(subjectCode);
- int scount = studentService.countCetMarking(req);
- if (scount == 0) {
- throw new ParameterException("没有考生信息");
- }
- if (studentService.existUncheck(examId, subjectCode)) {
- throw new ParameterException("有缺考待确认考生");
- }
- if (studentService.existImageCheckUnFinish(examId, subjectCode)) {
- throw new ParameterException("有未完成的图片检查");
- }
- if (StringUtils.isBlank(examService.getById(examId).getScanSite())) {
- throw new ParameterException("扫描点代码未设置");
- }
- DataExportTaskVo vo = new DataExportTaskVo();
- vo.setTaskId(FastUUID.get());
- vo.setTotalCount(scount);
- vo.setExamId(examId);
- vo.setSubjectCode(subjectCode);
- vo.setStatus(AsyncTaskStatus.RUNNING);
- vo.setProgress(0.0);
- AnswerDataExportConsumer com = SpringContextHolder.getBean(AnswerDataExportConsumer.class);
- com.setVo(vo);
- exec.execute(com);
- asyncTaskService.addTask(vo);
- return TaskIdVo.create(vo.getTaskId());
- }
- @Override
- public TaskIdVo sliceDataExport(Long examId, String subjectCode) {
- ExportCetMarkingQueryVo req = new ExportCetMarkingQueryVo();
- req.setExamId(examId);
- req.setSubjectCode(subjectCode);
- int scount = studentService.countCetMarking(req);
- if (scount == 0) {
- throw new ParameterException("没有考生信息");
- }
- if (studentService.existUncheck(examId, subjectCode)) {
- throw new ParameterException("有缺考待确认考生");
- }
- if (studentService.existImageCheckUnFinish(examId, subjectCode)) {
- throw new ParameterException("有未完成的图片检查");
- }
- if (StringUtils.isBlank(examService.getById(examId).getScanSite())) {
- throw new ParameterException("扫描点代码未设置");
- }
- DataExportTaskVo vo = new DataExportTaskVo();
- vo.setTaskId(FastUUID.get());
- vo.setTotalCount(scount);
- vo.setExamId(examId);
- vo.setSubjectCode(subjectCode);
- vo.setStatus(AsyncTaskStatus.RUNNING);
- vo.setProgress(0.0);
- SliceDataExportConsumer com = SpringContextHolder.getBean(SliceDataExportConsumer.class);
- com.setVo(vo);
- exec.execute(com);
- asyncTaskService.addTask(vo);
- return TaskIdVo.create(vo.getTaskId());
- }
- @Override
- public void answerDataExportDispose(DataExportTaskVo vo) {
- try {
- File temDir = new File("temp/" + FastUUID.get() + "/");
- temDir.mkdirs();
- File dbf = new File(temDir.getAbsolutePath() + "/answer-data.dbf");
- dbf.createNewFile();
- ExportCetMarkingQueryVo req = new ExportCetMarkingQueryVo();
- req.setExamId(vo.getExamId());
- req.setSubjectCode(vo.getSubjectCode());
- req.setPageSize(10000);
- int pageNumber = 0;
- req.setPageNumber(pageNumber);
- Set<String> examNumbers = new HashSet<>();
- Map<String, MarkSiteEntity> cms = readCetMarking(vo.getExamId(), vo.getSubjectCode());
- Map<String, String> breachMap = breachMap(vo.getExamId(), vo.getSubjectCode());
- Map<String, String> custStatusMap = custStatusMap(vo.getExamId(), vo.getSubjectCode());
- List<ExportCetVo> list = new ArrayList<>();
- long startId = 0;
- while (true) {
- // req.setPageNumber(++pageNumber);
- req.setStartId(startId);
- List<ExportCetVo> temp = studentService.exportCetData(req);
- if (CollectionUtils.isEmpty(temp)) {
- break;
- }
- startId = temp.get(temp.size()-1).getId();
- list.addAll(temp);
- log.warn("【DBF导出】查询考生数据,当前第{}页共{}条! taskId:{}",req.getPageNumber(), list.size(), vo.getTaskId());
- }
- if (CollectionUtils.isEmpty(list)) {
- throw new StatusException("没有需要导出的数据");
- }
- exportAnswer(examNumbers, breachMap, custStatusMap, dbf, list, cms, vo);
- ExamEntity exam = examService.getById(vo.getExamId());
- SubjectEntity subejct = this.findByExamIdAndCode(vo.getExamId(), vo.getSubjectCode());
- vo.setFileName(subejct.getName() + "_" + exam.getScanSite() + "_OMR.dbf");
- vo.setFile(dbf);
- vo.setTempDir(temDir);
- vo.setStatus(AsyncTaskStatus.SUCCESS);
- } catch (StatusException e) {
- vo.setErrMsg(e.getMessage());
- vo.setStatus(AsyncTaskStatus.FAILED);
- } catch (ParameterException e) {
- vo.setErrMsg(e.getMessage());
- vo.setStatus(AsyncTaskStatus.FAILED);
- } catch (Exception e) {
- vo.setErrMsg("系统异常");
- vo.setStatus(AsyncTaskStatus.FAILED);
- log.error("导出扫描答案DBF异常", e);
- }
- }
- private void exportAnswer(Set<String> examNumbers, Map<String, String> breachMap, Map<String, String> custStatusMap,
- File dbf, List<ExportCetVo> list, Map<String, MarkSiteEntity> cms, DataExportTaskVo vo)
- throws FileNotFoundException {
- FileOutputStream fos = null;
- DBFWriter writer = null;
- try {
- DBFField fields[] = new DBFField[11];
- fields[0] = new DBFField();
- fields[0].setName("Zkzh");
- fields[0].setType(DBFDataType.CHARACTER);
- fields[0].setLength(15);
- fields[1] = new DBFField();
- fields[1].setName("Xm");
- fields[1].setType(DBFDataType.CHARACTER);
- fields[1].setLength(30);
- fields[2] = new DBFField();
- fields[2].setName("Qk");
- fields[2].setType(DBFDataType.NUMERIC);
- fields[2].setLength(4);
- fields[3] = new DBFField();
- fields[3].setName("Km_h");
- fields[3].setType(DBFDataType.NUMERIC);
- fields[3].setLength(4);
- fields[4] = new DBFField();
- fields[4].setName("Smda");
- fields[4].setType(DBFDataType.CHARACTER);
- fields[4].setLength(100);
- fields[5] = new DBFField();
- fields[5].setName("Yc1");
- fields[5].setType(DBFDataType.NUMERIC);
- fields[5].setLength(4);
- fields[6] = new DBFField();
- fields[6].setName("Yc2");
- fields[6].setType(DBFDataType.NUMERIC);
- fields[6].setLength(4);
- fields[7] = new DBFField();
- fields[7].setName("Wj");
- fields[7].setType(DBFDataType.NUMERIC);
- fields[7].setLength(2);
- fields[8] = new DBFField();
- fields[8].setName("Barcode");
- fields[8].setType(DBFDataType.CHARACTER);
- fields[8].setLength(6);
- fields[9] = new DBFField();
- fields[9].setName("Pjd");
- fields[9].setType(DBFDataType.CHARACTER);
- fields[9].setLength(2);
- fields[10] = new DBFField();
- fields[10].setName("Kszt");
- fields[10].setType(DBFDataType.CHARACTER);
- fields[10].setLength(2);
- fos = new FileOutputStream(dbf);
- writer = new DBFWriter(fos, Charset.forName("gbk"));
- writer.setFields(fields);
- log.warn("【DBF导出】导出考生数据,当前共{}条! taskId:{}", list.size(), vo.getTaskId());
- for (ExportCetVo data : list) {
- if (examNumbers.contains(data.getExamNumber())) {
- continue;
- }
- vo.setProgressCount(vo.getProgressCount() + 1);
- examNumbers.add(data.getExamNumber());
- Object[] rowData = new Object[11];
- rowData[0] = data.getExamNumber();
- rowData[1] = data.getName();
- if (ExamStatus.ABSENT.equals(data.getExamStatus())) {
- rowData[2] = 1;
- } else {
- rowData[2] = 0;
- }
- rowData[3] = getIntFromString(data.getSubjectCode());
- rowData[4] = data.getAnswer();
- rowData[5] = data.getCardFirst();
- rowData[6] = data.getCardSecond();
- String breach = breachMap.get(data.getExamNumber());
- rowData[7] = StringUtils.isBlank(breach) ? 0 : getIntFromString(breach);
- rowData[8] = data.getPaperType();
- int subjectCode = Integer.valueOf(data.getExamNumber().substring(9, 10));
- String markingCode;
- if (subjectCode >= 3 && subjectCode <= 9) {
- markingCode = "88";
- } else {
- if (ExamStatus.ABSENT.equals(data.getExamStatus()) || "000000".equals(data.getPaperType())
- || "999999".equals(data.getPaperType())) {
- markingCode = "00";
- } else {
- int site = Integer.valueOf(data.getExamNumber().substring(10, 13));
- MarkSiteEntity cm = cms.get(data.getPaperType());
- if (cm == null) {
- throw new StatusException("未找到评卷点数据,条码值:" + data.getPaperType());
- }
- if (StringUtils.isBlank(cm.getOddNumber())) {
- throw new StatusException("奇数考场评卷点代码不能为空,条码值:" + data.getPaperType());
- }
- if (StringUtils.isBlank(cm.getEvenNumber())) {
- throw new StatusException("偶数考场评卷点代码不能为空,条码值:" + data.getPaperType());
- }
- if (site % 2 == 0) {
- markingCode = cm.getEvenNumber();
- } else {
- markingCode = cm.getOddNumber();
- }
- }
- }
- rowData[9] = markingCode;
- String custStatus = custStatusMap.get(data.getExamNumber());
- rowData[10] = StringUtils.isBlank(custStatus) ? "0" : custStatus;
- writer.addRecord(rowData);
- }
- } finally {
- if (writer != null) {
- writer.close();
- }
- try {
- if (fos != null) {
- fos.close();
- }
- } catch (IOException e) {
- }
- }
- }
- private Map<String, String> breachMap(Long examId, String subjectCode) throws Exception {
- Map<String, String> ret = new HashMap<>();
- String path = fileService.getBreachUri(examId, subjectCode);
- if (fileStore.exist(path)) {
- List<String> list = IOUtils.readLines(fileStore.read(path), "utf-8");
- if (CollectionUtils.isNotEmpty(list)) {
- for (int i = 1; i < list.size(); i++) {
- String[] ss = list.get(i).split(",");
- ret.put(ss[0].trim(), ss[2].trim());
- }
- }
- }
- return ret;
- }
- private Map<String, String> custStatusMap(Long examId, String subjectCode) throws Exception {
- Map<String, String> ret = new HashMap<>();
- String path = fileService.getCustStatusUri(examId, subjectCode);
- if (fileStore.exist(path)) {
- List<String> list = IOUtils.readLines(fileStore.read(path), "utf-8");
- if (CollectionUtils.isNotEmpty(list)) {
- for (int i = 1; i < list.size(); i++) {
- String[] ss = list.get(i).split(",");
- ret.put(ss[0].trim(), ss[2].trim());
- }
- }
- }
- return ret;
- }
- private Integer getIntFromString(String v) {
- if (v == null) {
- return null;
- }
- return Integer.valueOf(v);
- }
- private Map<String, MarkSiteEntity> readCetMarking(Long examId, String subejctCode) {
- Map<String, MarkSiteEntity> ret = new HashMap<>();
- List<MarkSiteEntity> list = markSiteService.findByExamAndSubject(examId, subejctCode);
- if (CollectionUtils.isNotEmpty(list)) {
- for (MarkSiteEntity e : list) {
- ret.put(e.getPaperType(), e);
- }
- }
- return ret;
- }
- @Override
- public void sliceDataExportDispose(DataExportTaskVo vo) {
- try {
- File temDir = new File("temp/" + FastUUID.get() + "/");
- temDir.mkdirs();
- File dbf = new File(temDir.getAbsolutePath() + "/slice-data.dbf");
- dbf.createNewFile();
- ExportCetMarkingQueryVo req = new ExportCetMarkingQueryVo();
- req.setExamId(vo.getExamId());
- req.setSubjectCode(vo.getSubjectCode());
- req.setPageSize(10000);
- int pageNumber = 0;
- req.setPageNumber(pageNumber);
- Set<String> examNumbers = new HashSet<>();
- Map<String, MarkSiteEntity> cms = readCetMarking(vo.getExamId(), vo.getSubjectCode());
- List<ExportCetVo> list = new ArrayList<>();
- long startId = 0;
- while (true) {
- // req.setPageNumber(++pageNumber);
- req.setStartId(startId);
- List<ExportCetVo> temp = studentService.exportCetData(req);
- if (CollectionUtils.isEmpty(temp)) {
- break;
- }
- startId = temp.get(temp.size()-1).getId();
- list.addAll(temp);
- }
- if (CollectionUtils.isEmpty(list)) {
- throw new StatusException("没有需要导出的数据");
- }
- exportSlice(examNumbers, dbf, list, cms, vo);
- ExamEntity exam = examService.getById(vo.getExamId());
- vo.setFileName(exam.getScanSite() + "_" + vo.getTotalCount() + "_"
- + DateUtil.format(new Date(), DateUtil.DatePatterns.YYYYMMDDHH) + ".dbf");
- vo.setFile(dbf);
- vo.setTempDir(temDir);
- vo.setStatus(AsyncTaskStatus.SUCCESS);
- } catch (StatusException e) {
- vo.setErrMsg(e.getMessage());
- vo.setStatus(AsyncTaskStatus.FAILED);
- } catch (ParameterException e) {
- vo.setErrMsg(e.getMessage());
- vo.setStatus(AsyncTaskStatus.FAILED);
- } catch (Exception e) {
- vo.setErrMsg("系统异常");
- vo.setStatus(AsyncTaskStatus.FAILED);
- log.error("导出打包DBF异常", e);
- }
- }
- private void exportSlice(Set<String> examNumbers, File dbf, List<ExportCetVo> list, Map<String, MarkSiteEntity> cms,
- DataExportTaskVo vo) throws FileNotFoundException {
- FileOutputStream fos = null;
- DBFWriter writer = null;
- try {
- DBFField fields[] = new DBFField[3];
- fields[0] = new DBFField();
- fields[0].setName("Zkzh");
- fields[0].setType(DBFDataType.CHARACTER);
- fields[0].setLength(15);
- fields[1] = new DBFField();
- fields[1].setName("Yjd");
- fields[1].setType(DBFDataType.CHARACTER);
- fields[1].setLength(2);
- fields[2] = new DBFField();
- fields[2].setName("Wjdx");
- fields[2].setType(DBFDataType.CHARACTER);
- fields[2].setLength(254);
- fos = new FileOutputStream(dbf);
- writer = new DBFWriter(fos, Charset.forName("gbk"));
- writer.setFields(fields);
- for (ExportCetVo data : list) {
- if (examNumbers.contains(data.getExamNumber())) {
- continue;
- }
- vo.setProgressCount(vo.getProgressCount() + 1);
- examNumbers.add(data.getExamNumber());
- String markingCode;
- if ("888888".equals(data.getPaperType())) {
- markingCode = "88";
- } else if (ExamStatus.ABSENT.equals(data.getExamStatus()) || "000000".equals(data.getPaperType())
- || "999999".equals(data.getPaperType())) {
- markingCode = "00";
- } else {
- int site = Integer.valueOf(data.getExamNumber().substring(10, 13));
- MarkSiteEntity cm = cms.get(data.getPaperType());
- if (cm == null) {
- throw new StatusException("未找到评卷点数据,条码值:" + data.getPaperType());
- }
- if (StringUtils.isBlank(cm.getOddNumber())) {
- throw new StatusException("奇数考场评卷点代码不能为空,条码值:" + data.getPaperType());
- }
- if (StringUtils.isBlank(cm.getEvenNumber())) {
- throw new StatusException("偶数考场评卷点代码不能为空,条码值:" + data.getPaperType());
- }
- if (site % 2 == 0) {
- markingCode = cm.getEvenNumber();
- } else {
- markingCode = cm.getOddNumber();
- }
- }
- Object[] rowData = new Object[3];
- rowData[0] = data.getExamNumber();
- rowData[1] = markingCode;
- rowData[2] = StringUtils.join(data.getSliceImageInfo(), ";") + ";";
- writer.addRecord(rowData);
- }
- } finally {
- if (writer != null) {
- writer.close();
- }
- try {
- if (fos != null) {
- fos.close();
- }
- } catch (IOException e) {
- }
- }
- }
- @Transactional
- @Override
- public void initSubject(Long examId) {
- List<SubjectEntity> subs = new ArrayList<>();
- subs.add(new SubjectEntity(examId, "1", "CET4"));
- subs.add(new SubjectEntity(examId, "2", "CET6"));
- subs.add(new SubjectEntity(examId, "3", "CJT4"));
- subs.add(new SubjectEntity(examId, "4", "CJT6"));
- subs.add(new SubjectEntity(examId, "5", "CGT4"));
- subs.add(new SubjectEntity(examId, "6", "CGT6"));
- subs.add(new SubjectEntity(examId, "7", "CRT4"));
- subs.add(new SubjectEntity(examId, "8", "CRT6"));
- subs.add(new SubjectEntity(examId, "9", "CFT4"));
- this.saveBatch(subs);
- }
- @Override
- public List<OmrSubjectVo> listByExamIdForOmr(Long examId) {
- List<SubjectEntity> ss = listByExamId(examId);
- if (CollectionUtils.isEmpty(ss)) {
- return new ArrayList<>();
- }
- List<OmrSubjectVo> ret = new ArrayList<>();
- for (SubjectEntity s : ss) {
- OmrSubjectVo vo = new OmrSubjectVo();
- vo.setCode(s.getCode());
- vo.setName(s.getName());
- List<OmrGroupVo> os = omrGroupService.listByExamIdAndSubjectCode(examId, s.getCode());
- int todoCount = 0;
- if (CollectionUtils.isNotEmpty(os)) {
- for (OmrGroupVo o : os) {
- todoCount = todoCount + o.getTodoCount();
- }
- }
- vo.setTodoCount(todoCount);
- ret.add(vo);
- }
- return ret;
- }
- @Override
- public UpdateTimeVo edit(Long examId, String subjectCode, String subjectName) {
- QueryWrapper<SubjectEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(SubjectEntity::getExamId, examId);
- queryWrapper.lambda().eq(SubjectEntity::getName, subjectName);
- SubjectEntity subject = this.getOne(queryWrapper);
- if (subject != null) {
- throw new ParameterException("科目代码在本考试中已存在");
- }
- subject = this.findByExamIdAndCode(examId, subjectCode);
- if (subject == null) {
- throw new ParameterException("subject不存在");
- }
- subject.setName(subjectName);
- saveOrUpdateByMultiId(subject);
- return UpdateTimeVo.create();
- }
- }
|