From 05a54025b1ae843f9d21a4450ec05c9e420e7f24 Mon Sep 17 00:00:00 2001
From: zf <1603559716@qq.com>
Date: 星期四, 28 九月 2023 10:47:37 +0800
Subject: [PATCH] bug修改

---
 exam-system/src/main/java/com/gkhy/exam/coalmine/service/impl/EmonRecordManagerServiceImpl.java |  220 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 220 insertions(+), 0 deletions(-)

diff --git a/exam-system/src/main/java/com/gkhy/exam/coalmine/service/impl/EmonRecordManagerServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/coalmine/service/impl/EmonRecordManagerServiceImpl.java
new file mode 100644
index 0000000..02916fa
--- /dev/null
+++ b/exam-system/src/main/java/com/gkhy/exam/coalmine/service/impl/EmonRecordManagerServiceImpl.java
@@ -0,0 +1,220 @@
+package com.gkhy.exam.coalmine.service.impl;
+
+import com.gkhy.exam.coalmine.entity.EmonExamRecord;
+import com.gkhy.exam.coalmine.entity.EmonTrainRecord;
+import com.gkhy.exam.coalmine.model.dto.req.ExamReceiveReqDTO;
+import com.gkhy.exam.coalmine.model.dto.req.TrainReceiveReqDTO;
+import com.gkhy.exam.coalmine.model.dto.resp.AttachmentInfoRespDTO;
+import com.gkhy.exam.coalmine.model.dto.resp.GetExamDataRespDTO;
+import com.gkhy.exam.coalmine.model.dto.resp.GetTrainDataRespDTO;
+import com.gkhy.exam.coalmine.service.EmonRecordManagerService;
+import com.gkhy.exam.coalmine.service.baseService.EmonExamRecordService;
+import com.gkhy.exam.coalmine.service.baseService.EmonTrainRecordService;
+import com.gkhy.exam.coalmine.utils.AttachmentUtil;
+import com.ruoyi.common.constant.ResultConstants;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.enums.coalmineEnums.DeleteStatusEnum;
+import com.ruoyi.common.exception.BusinessException;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.file.entity.AttachmentInfo;
+import com.ruoyi.file.service.AttachmentService;
+import com.ruoyi.system.service.SysDistrictService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author Mr.huang
+ * @decription
+ * @date 2023/9/13 10:19
+ */
+@Service
+public class EmonRecordManagerServiceImpl implements EmonRecordManagerService {
+
+    @Resource
+    private AttachmentService attachmentService;
+
+    @Resource
+    private SysDistrictService sysDistrictService;
+
+    @Resource
+    private EmonExamRecordService  emonExamRecordService;
+
+    @Resource
+    private EmonTrainRecordService emonTrainRecordService;
+
+
+    private Boolean examDataIsValid(MultipartFile[] file,ExamReceiveReqDTO reqDTO){
+        boolean valid = reqDTO != null && reqDTO.getReportTime() != null && reqDTO.getDistrictId() != null
+                && StringUtils.isNotBlank(reqDTO.getExamCenter()) && StringUtils.isNotBlank(reqDTO.getExcType())
+                && reqDTO.getIsCm() != null && StringUtils.isNotBlank(reqDTO.getModule()) && !CollectionUtils.isEmpty(Arrays.asList(file));
+        return valid;
+    }
+
+    @Override
+    @Transactional
+    public AjaxResult examReceive(MultipartFile[] file,ExamReceiveReqDTO reqDTO) {
+        if (examDataIsValid(file,reqDTO)) {
+            List<AttachmentInfo> attachmentInfos = (List<AttachmentInfo>) attachmentService.saveBatchFileToPath(file, reqDTO.getModule());
+            if (CollectionUtils.isEmpty(attachmentInfos))
+                throw new BusinessException(this.getClass(), ResultConstants.SYSTEM_ERROR_DATABASE_FAIL, "考场异常监控记录图片保存失败");
+            String attachmentIds = AttachmentUtil.idConvertString(attachmentInfos);
+            EmonExamRecord emonExamRecord = new EmonExamRecord();
+            BeanUtils.copyProperties(reqDTO, emonExamRecord);
+            emonExamRecord.setDelFlag(DeleteStatusEnum.NO.getStatus());
+            emonExamRecord.setExcImage(attachmentIds);
+            boolean save = emonExamRecordService.save(emonExamRecord);
+            if (!save)
+                throw new BusinessException(this.getClass(), ResultConstants.SYSTEM_ERROR_DATABASE_FAIL, "考场异常监控记录保存失败");
+
+            return AjaxResult.success();
+        }
+        return null;
+    }
+
+    private Boolean trainDataIsValid(MultipartFile[] file,TrainReceiveReqDTO reqDTO){
+        boolean valid = reqDTO != null && reqDTO.getReportTime() != null && reqDTO.getDistrictId() != null
+                && StringUtils.isNotBlank(reqDTO.getExamCenter()) && StringUtils.isNotBlank(reqDTO.getExcType())
+                && reqDTO.getIsCm() != null && !CollectionUtils.isEmpty(Arrays.asList(file))
+                && StringUtils.isNotBlank(reqDTO.getModule());
+        return valid;
+    }
+
+    @Override
+    public AjaxResult trainReceive(MultipartFile[] file,TrainReceiveReqDTO reqDTO) {
+        List<AttachmentInfo> attachmentInfos = (List<AttachmentInfo>) attachmentService.saveBatchFileToPath(file, reqDTO.getModule());
+        if (CollectionUtils.isEmpty(attachmentInfos))
+            throw new BusinessException(this.getClass(), ResultConstants.SYSTEM_ERROR_DATABASE_FAIL, "培训监控异常记录图片保存失败");
+        String attachmentIds = AttachmentUtil.idConvertString(attachmentInfos);
+        if (trainDataIsValid(file,reqDTO)) {
+            EmonTrainRecord emonTrainRecord = new EmonTrainRecord ();
+            BeanUtils.copyProperties(reqDTO,emonTrainRecord);
+            emonTrainRecord.setDelFlag(DeleteStatusEnum.NO.getStatus());
+            emonTrainRecord.setExcImage(attachmentIds);
+            boolean save = emonTrainRecordService.save(emonTrainRecord);
+            if (!save)
+                throw new BusinessException(this.getClass(), ResultConstants.SYSTEM_ERROR_DATABASE_FAIL, "培训监控异常记录保存失败");
+            return AjaxResult.success();
+        }
+        return null;
+    }
+
+    @Override
+    public List<GetExamDataRespDTO> getExamData() {
+        Long districtId = SecurityUtils.getLoginUser().getUser().getDistrictId();
+        List<Long> childrenIds = sysDistrictService.selectChildrenIdsById(districtId);
+        List<EmonExamRecord> emonExamRecords =  emonExamRecordService.listValid(childrenIds);
+        if (!CollectionUtils.isEmpty(emonExamRecords)){
+            List<GetExamDataRespDTO> list = emonExamRecords.stream().map(emonExamRecord -> {
+                GetExamDataRespDTO dto = new GetExamDataRespDTO();
+                BeanUtils.copyProperties(emonExamRecord, dto);
+                String excImage = emonExamRecord.getExcImage();
+                if (StringUtils.isNotBlank(excImage)) {
+                    List<Long> ids = AttachmentUtil.stringConvertIds(excImage);
+                    List<AttachmentInfo> attachmentInfos = attachmentService.findByIds(ids);
+                    if (!CollectionUtils.isEmpty(attachmentInfos)) {
+                        List<AttachmentInfoRespDTO> attachmentInfoRespDTOS = attachmentInfos.stream().map(attachmentInfo -> {
+                            AttachmentInfoRespDTO respDTO = new AttachmentInfoRespDTO();
+                            BeanUtils.copyProperties(attachmentInfo, respDTO);
+                            return respDTO;
+                        }).collect(Collectors.toList());
+                        dto.setAttachmentInfos(attachmentInfoRespDTOS);
+                    }
+                }
+                return dto;
+            }).collect(Collectors.toList());
+            return list;
+        }
+        return new ArrayList<>();
+    }
+
+    @Override
+    public List<GetTrainDataRespDTO> getTrainData() {
+        Long districtId = SecurityUtils.getLoginUser().getUser().getDistrictId();
+        List<Long> childrenIds = sysDistrictService.selectChildrenIdsById(districtId);
+        List<EmonTrainRecord> emonTrainRecords =  emonTrainRecordService.listValid(childrenIds);
+        if (!CollectionUtils.isEmpty(emonTrainRecords)){
+            List<GetTrainDataRespDTO> list = emonTrainRecords.stream().map(emonTrainRecord -> {
+                GetTrainDataRespDTO dto = new GetTrainDataRespDTO();
+                BeanUtils.copyProperties(emonTrainRecord, dto);
+                String excImage = emonTrainRecord.getExcImage();
+                if (StringUtils.isNotBlank(excImage)) {
+                    List<Long> ids = AttachmentUtil.stringConvertIds(excImage);
+                    List<AttachmentInfo> attachmentInfos = attachmentService.findByIds(ids);
+                    if (!CollectionUtils.isEmpty(attachmentInfos)) {
+                        List<AttachmentInfoRespDTO> attachmentInfoRespDTOS = attachmentInfos.stream().map(attachmentInfo -> {
+                            AttachmentInfoRespDTO respDTO = new AttachmentInfoRespDTO();
+                            BeanUtils.copyProperties(attachmentInfo, respDTO);
+                            return respDTO;
+                        }).collect(Collectors.toList());
+                        dto.setAttachmentInfos(attachmentInfoRespDTOS);
+                    }
+                }
+                return dto;
+            }).collect(Collectors.toList());
+            return list;
+        }
+        return new ArrayList<>();
+    }
+
+    @Override
+    public AjaxResult deleteExamRecord(Long id) {
+        EmonExamRecord emonExamRecord = emonExamRecordService.findValidById(id);
+        if (emonExamRecord == null)
+            return AjaxResult.success();
+        emonExamRecord.setDelFlag(DeleteStatusEnum.YES.getStatus());
+        boolean update = emonExamRecordService.updateById(emonExamRecord);
+        if (!update)
+            throw new BusinessException(this.getClass(), ResultConstants.SYSTEM_ERROR_DATABASE_FAIL, "考场异常监控记录删除失败");
+        String excImage = emonExamRecord.getExcImage();
+        if (StringUtils.isNotBlank(excImage)) {
+            List<Long> ids = AttachmentUtil.stringConvertIds(excImage);
+            List<AttachmentInfo> attachmentInfos = attachmentService.findByIds(ids);
+            if (!CollectionUtils.isEmpty(attachmentInfos)) {
+                attachmentInfos = attachmentInfos.stream().map(attachmentInfo -> {
+                    attachmentInfo.setDelFlag(1);
+                    attachmentInfo.setUpdateBy(SecurityUtils.getUsername());
+                    attachmentInfo.setUpdateTime(new Date());
+                    return attachmentInfo;
+                }).collect(Collectors.toList());
+                attachmentService.updateBatchById(attachmentInfos);
+            }
+        }
+        return AjaxResult.success("考场异常监控记录删除成功");
+    }
+
+    @Override
+    public AjaxResult deleteTrainRecord(Long id) {
+        EmonTrainRecord emonTrainRecord = emonTrainRecordService.findValidById(id);
+        if (emonTrainRecord == null)
+            return AjaxResult.success();
+        emonTrainRecord.setDelFlag(DeleteStatusEnum.YES.getStatus());
+        boolean update = emonTrainRecordService.updateById(emonTrainRecord);
+        if (!update)
+            throw new BusinessException(this.getClass(), ResultConstants.SYSTEM_ERROR_DATABASE_FAIL, "培训异常监控记录删除失败");
+        String excImage = emonTrainRecord.getExcImage();
+        if (StringUtils.isNotBlank(excImage)) {
+            List<AttachmentInfo> attachmentInfos = attachmentService.findByBusinessId(id);
+            if (!CollectionUtils.isEmpty(attachmentInfos)) {
+                attachmentInfos = attachmentInfos.stream().map(attachmentInfo -> {
+                    attachmentInfo.setDelFlag(1);
+                    attachmentInfo.setUpdateBy(SecurityUtils.getUsername());
+                    attachmentInfo.setUpdateTime(new Date());
+                    return attachmentInfo;
+                }).collect(Collectors.toList());
+                attachmentService.updateBatchById(attachmentInfos);
+            }
+        }
+        return AjaxResult.success("培训异常监控记录删除成功");
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.2