From 3b0516a2959e25576e4f3fda697a3b025d06c8c9 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期二, 24 六月 2025 14:09:07 +0800
Subject: [PATCH] 每日录像可用指标添加日志,修改大屏为查看当前月平均

---
 ycl-server/src/main/java/com/ycl/platform/service/impl/ReportServiceImpl.java |  132 ++++++++++++++++++++++++++++++++------------
 1 files changed, 96 insertions(+), 36 deletions(-)

diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/ReportServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/ReportServiceImpl.java
index 7ad031e..4b06f6c 100644
--- a/ycl-server/src/main/java/com/ycl/platform/service/impl/ReportServiceImpl.java
+++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/ReportServiceImpl.java
@@ -3,6 +3,7 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
 import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ycl.platform.domain.dto.ReportImportDTO;
 import com.ycl.platform.domain.entity.*;
@@ -35,11 +36,9 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
+import org.springframework.util.CollectionUtils;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -70,10 +69,13 @@
         if (Objects.isNull(form.getPointId())) {
             throw new RuntimeException("鐐逛綅涓嶈兘涓虹┖");
         }
-        Long userId = SecurityUtils.getUserId();
-        YwPeople people = new LambdaQueryChainWrapper<>(peopleMapper).eq(YwPeople::getUserId, userId).one();
-        form.setPeopleId(people.getId());
-        form.setUnitId(people.getBelongUnit());
+        Integer unitId = SecurityUtils.getUnitId();
+        if (Objects.isNull(unitId)) {
+            throw new RuntimeException("闈炶繍缁村崟浣嶆殏鏃舵棤娉曟姤澶�");
+        }
+        form.setUnitId(unitId);
+        Long userId = SecurityUtils.getLoginUser().getUserId();
+        form.setPeopleId(Integer.parseInt(userId+""));
         if ("浜嬪墠鎶ュ".equals(form.getReportType())) {
             // 濡傛灉鏄簨鍓嶆姤澶囬渶瑕佹楠屾槸鍚﹀凡缁忕敓鎴愪笅鍙戝伐鍗�
             YwPointVO point = ywpointMapper.countNotFinishedWorkOrderByGb(form.getPointId());
@@ -90,10 +92,10 @@
         Report entity = ReportForm.getEntityByForm(form, null);
         entity.setSerialNumber(point.getSerialNumber());
         entity.setStatus(0);
-        entity.setIdentify(IdUtils.randomNO());
         Date now = new Date();
         entity.setCreateTime(now);
         entity.setUpdateTime(now);
+        entity.setIdentify(IdUtils.randomNO(now));
         baseMapper.insert(entity);
         List<ReportErrorType> errorTypeList = form.getErrorTypeList().stream().map(item -> {
             ReportErrorType reportErrorType = new ReportErrorType();
@@ -118,15 +120,19 @@
     @SneakyThrows
     @Transactional
     public Result importData(ReportForm form) {
-        Long userId = SecurityUtils.getUserId();
-        YwPeople people = new LambdaQueryChainWrapper<>(peopleMapper).eq(YwPeople::getUserId, userId).one();
-        form.setPeopleId(people.getId());
-        form.setUnitId(people.getBelongUnit());
+        Integer unitId = SecurityUtils.getUnitId();
+        if (Objects.isNull(unitId)) {
+            throw new RuntimeException("闈炶繍缁村崟浣嶆殏鏃舵棤娉曟姤澶�");
+        }
+        form.setUnitId(unitId);
+        form.setBeginCreateTime(DateUtils.parseDate(form.getBeginCreateTimeStr()));
+        form.setEndCreateTime(DateUtils.parseDate(form.getEndCreateTimeStr()));
         // 璇诲彇excel鏁版嵁
         ExcelUtil<ReportImportDTO> excelUtil = new ExcelUtil<>(ReportImportDTO.class);
         List<ReportImportDTO> list = excelUtil.importExcel(form.getImportPointId().getInputStream());
+        Date now = DateUtils.getNowDate();
         // 鎵归噺鎻掑叆
-        String pid = IdUtils.randomNO();
+        String pid = IdUtils.randomNO(now);
         Integer success = 0;
         for (ReportImportDTO item : list) {
             if ("浜嬪墠鎶ュ".equals(form.getReportType())) {
@@ -137,7 +143,7 @@
                 }
             }
             YwPoint point = new LambdaQueryChainWrapper<>(ywpointMapper)
-                    .eq(YwPoint::getSerialNumber, form.getPointId())
+                    .eq(YwPoint::getSerialNumber, item.getSerialNumber())
                     .one();
             if (Objects.isNull(point)) {
                 continue;
@@ -146,8 +152,7 @@
             entity.setImportBatchNumber(pid);
             entity.setSerialNumber(item.getSerialNumber());
             entity.setStatus(0);
-            entity.setIdentify(IdUtils.randomNO());
-            Date now = DateUtils.getNowDate();
+            entity.setIdentify(IdUtils.randomNO(now));
             entity.setCreateTime(now);
             entity.setUpdateTime(now);
             baseMapper.insert(entity);
@@ -163,6 +168,12 @@
             success++;
         }
         return Result.ok("鎶ュ鐐逛綅鏁帮細" + list.size() + "锛屽鍏ユ垚鍔熸暟锛�" + success);
+    }
+
+    @Override
+    public Result getTogether(String pid) {
+        List<Report> list = baseMapper.getTogether(pid);
+        return Result.ok().data(list);
     }
 
     /**
@@ -246,6 +257,7 @@
     @Override
     public Result page(ReportQuery query) {
         IPage<ReportVO> page = PageUtil.getPage(query, ReportVO.class);
+        query.setUnitId(SecurityUtils.getUnitId());
         baseMapper.page(page, query);
         List<SysDictData> errorTypeList = dictTypeService.selectDictDataByType("report_error_type");
         Map<String, String> dictMap = errorTypeList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
@@ -304,8 +316,36 @@
     public List<ReportVO> export(ReportQuery query) {
         IPage<ReportVO> page = PageUtil.getPage(query, ReportVO.class);
         page.setSize(-1);
+        query.setUnitId(SecurityUtils.getUnitId());
         baseMapper.page(page, query);
+        List<SysDictData> errorTypeList = dictTypeService.selectDictDataByType("report_error_type");
+        Map<String, String> dictMap = errorTypeList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
         page.getRecords().forEach(item -> {
+            if (StringUtils.hasText(item.getErrorType())) {
+                item.setErrorTypeList(List.of(item.getErrorType().split(",")));
+                StringBuilder sb = new StringBuilder();
+                item.getErrorTypeList().stream().forEach(err -> {
+                    String s = dictMap.get(err);
+                    if (org.springframework.util.StringUtils.hasText(s)) {
+                        sb.append(s).append("銆�");
+                    }
+                });
+                item.setErrorType(sb.substring(0, sb.length() - 1));
+            }
+            // 瀹℃牳缁撴灉
+            List<ReportAuditingRecord> records = new LambdaQueryChainWrapper<>(reportAuditingRecordService.getBaseMapper())
+                    .eq(ReportAuditingRecord::getReportId, item.getId())
+                    .orderByDesc(ReportAuditingRecord::getCreateTime)
+                    .last("limit 1")
+                    .list();
+            if (! CollectionUtils.isEmpty(records)) {
+                item.setResultStr(records.get(0).getResult() ? "閫氳繃" : "鏈�氳繃");
+                item.setResultRemark(records.get(0).getResultRemark());
+                item.setAuditingTime(records.get(0).getCreateTime());
+
+            } else {
+                item.setResultStr("瀹℃牳涓�");
+            }
             item.setReportContent(EscapeUtil.clean(item.getReportContent()));
         });
         return page.getRecords();
@@ -321,27 +361,47 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Result auditing(ReportAuditingForm form) {
-        Report report = baseMapper.selectById(form.getId());
-        if (Objects.isNull(report)) {
-            throw new RuntimeException("瀹℃牳鐨勬姤澶囦笉瀛樺湪");
+        if (CollectionUtils.isEmpty(form.getTogetherList())) {
+            form.setTogetherList(new ArrayList<>(2));
         }
-        if (form.getAuditingResult()) {
-            report.setStatus(1);
-        } else {
-            report.setStatus(2);
-        }
-        Date now = new Date();
-        report.setUpdateTime(now);
-        baseMapper.updateById(report);
+        form.getTogetherList().add(form.getId());
+        for (Integer id : form.getTogetherList()) {
+            Report report = baseMapper.selectById(id);
+            if (Objects.isNull(report)) {
+                continue;
+            }
+            if (form.getAuditingResult()) {
+                report.setStatus(1);
+            } else {
+                report.setStatus(2);
+            }
+            Date now = new Date();
+            report.setUpdateTime(now);
+            baseMapper.updateById(report);
 
-        // 娣诲姞涓�鏉″鏍歌褰�
-        ReportAuditingRecord reportAuditingRecord = new ReportAuditingRecord();
-        reportAuditingRecord.setReportId(form.getId());
-        reportAuditingRecord.setDeleted(0);
-        reportAuditingRecord.setCreateTime(now);
-        reportAuditingRecord.setResultRemark(form.getAuditOpinion());
-        reportAuditingRecord.setResult(form.getAuditingResult());
-        reportAuditingRecordService.save(reportAuditingRecord);
+            // 娣诲姞涓�鏉″鏍歌褰�
+            ReportAuditingRecord reportAuditingRecord = new ReportAuditingRecord();
+            reportAuditingRecord.setReportId(id);
+            reportAuditingRecord.setDeleted(0);
+            reportAuditingRecord.setCreateTime(now);
+            reportAuditingRecord.setResultRemark(form.getAuditOpinion());
+            reportAuditingRecord.setResult(form.getAuditingResult());
+            reportAuditingRecordService.save(reportAuditingRecord);
+        }
         return Result.ok("鎿嶄綔鎴愬姛");
     }
+
+    @Override
+    public Result getListByGb(String gb) {
+        List<ReportVO> list = baseMapper.getListByGb(gb);
+        for (ReportVO report : list) {
+            List<ReportErrorType> errors = new LambdaQueryChainWrapper<>(reportErrorTypeService.getBaseMapper())
+                    .eq(ReportErrorType::getReportId, report.getId())
+                    .orderByDesc(ReportErrorType::getCreateTime)
+                    .list();
+            String err = errors.stream().map(ReportErrorType::getErrorType).collect(Collectors.joining(","));
+            report.setErrorType(err);
+        }
+        return Result.ok().data(list);
+    }
 }

--
Gitblit v1.8.0