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 |  350 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 294 insertions(+), 56 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 a18f98b..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
@@ -1,34 +1,45 @@
 package com.ycl.platform.service.impl;
 
-import com.ycl.platform.domain.entity.Region;
-import com.ycl.platform.domain.entity.Report;
-import com.ycl.platform.domain.entity.YwPeople;
-import com.ycl.platform.domain.entity.YwUnit;
-import com.ycl.platform.mapper.RegionMapper;
+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.*;
+import com.ycl.platform.domain.form.ReportAuditingForm;
+import com.ycl.platform.domain.form.ReportForm;
+import com.ycl.platform.domain.query.ReportQuery;
+import com.ycl.platform.domain.vo.ReportVO;
+import com.ycl.platform.domain.vo.YwPointVO;
 import com.ycl.platform.mapper.ReportMapper;
 import com.ycl.platform.mapper.YwPeopleMapper;
+import com.ycl.platform.mapper.YwPointMapper;
 import com.ycl.platform.mapper.YwUnitMapper;
+import com.ycl.platform.service.ReportAuditingRecordService;
+import com.ycl.platform.service.ReportErrorTypeService;
 import com.ycl.platform.service.ReportService;
 import com.ycl.system.Result;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ycl.platform.domain.form.ReportForm;
-import com.ycl.platform.domain.vo.ReportVO;
-import com.ycl.platform.domain.query.ReportQuery;
-import java.util.List;
-import org.apache.commons.lang3.StringUtils;
-import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.ycl.system.entity.SysDictData;
 import com.ycl.system.page.PageUtil;
-import org.springframework.stereotype.Service;
-import org.springframework.security.core.context.SecurityContextHolder;
+import com.ycl.system.service.ISysDictTypeService;
+import com.ycl.utils.DateUtils;
+import com.ycl.utils.SecurityUtils;
+import com.ycl.utils.StringUtils;
+import com.ycl.utils.html.EscapeUtil;
+import com.ycl.utils.poi.ExcelUtil;
+import com.ycl.utils.uuid.IdUtils;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
 import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
-import java.util.ArrayList;
-import java.util.Objects;
+import org.springframework.util.CollectionUtils;
+
+import java.util.*;
 import java.util.stream.Collectors;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
-import lombok.RequiredArgsConstructor;
 
 /**
  * 鎶ュ 鏈嶅姟瀹炵幇绫�
@@ -40,10 +51,12 @@
 @RequiredArgsConstructor
 public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> implements ReportService {
 
-    private final ReportMapper reportMapper;
     private final YwUnitMapper unitMapper;
+    private final YwPointMapper ywpointMapper;
     private final YwPeopleMapper peopleMapper;
-    private final RegionMapper regionMapper;
+    private final ReportErrorTypeService reportErrorTypeService;
+    private final ISysDictTypeService dictTypeService;
+    private final ReportAuditingRecordService reportAuditingRecordService;
 
     /**
      * 娣诲姞
@@ -51,14 +64,116 @@
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Result add(ReportForm form) {
-        form.setPeopleId(1);
-        form.setUnitId(2);
-        Report entity = ReportForm.getEntityByForm(form, null);
-        if(baseMapper.insert(entity) > 0) {
-            return Result.ok("娣诲姞鎴愬姛");
+        if (Objects.isNull(form.getPointId())) {
+            throw new RuntimeException("鐐逛綅涓嶈兘涓虹┖");
         }
-        return Result.error("娣诲姞澶辫触");
+        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());
+            if (Objects.nonNull(point)) {
+                throw new RuntimeException(String.format("鐐逛綅銆�%s銆戝凡缁忓瓨鍦ㄤ笅鍙戝伐鍗曪紝鏃犳硶浜嬪墠鎶ュ", point.getPointName()));
+            }
+        }
+        YwPoint point = new LambdaQueryChainWrapper<>(ywpointMapper)
+                .eq(YwPoint::getSerialNumber, form.getPointId())
+                .one();
+        if (Objects.isNull(point)) {
+            throw new RuntimeException("鐐逛綅涓嶅瓨鍦�");
+        }
+        Report entity = ReportForm.getEntityByForm(form, null);
+        entity.setSerialNumber(point.getSerialNumber());
+        entity.setStatus(0);
+        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();
+            reportErrorType.setErrorType(item);
+            reportErrorType.setDeleted(0);
+            reportErrorType.setCreateTime(now);
+            reportErrorType.setReportId(entity.getId());
+            return reportErrorType;
+        }).collect(Collectors.toList());
+        reportErrorTypeService.saveBatch(errorTypeList);
+        return Result.ok("鎶ュ鎴愬姛");
+    }
+
+    @Override
+    @SneakyThrows
+    public void importTemplate(HttpServletResponse response) {
+        ExcelUtil<ReportImportDTO> excelUtil = new ExcelUtil<>(ReportImportDTO.class);
+        excelUtil.exportExcel(response, null, "鎶ュ瀵煎叆妯℃澘");
+    }
+
+    @Override
+    @SneakyThrows
+    @Transactional
+    public Result importData(ReportForm form) {
+        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(now);
+        Integer success = 0;
+        for (ReportImportDTO item : list) {
+            if ("浜嬪墠鎶ュ".equals(form.getReportType())) {
+                // 濡傛灉鏄簨鍓嶆姤澶囬渶瑕佹楠屾槸鍚﹀凡缁忕敓鎴愪笅鍙戝伐鍗�
+                YwPointVO point = ywpointMapper.countNotFinishedWorkOrderByGb(item.getSerialNumber());
+                if (Objects.nonNull(point)) {
+                    throw new RuntimeException(String.format("鐐逛綅銆�%s銆戝凡缁忓瓨鍦ㄤ笅鍙戝伐鍗曪紝鏃犳硶浜嬪墠鎶ュ", point.getPointName()));
+                }
+            }
+            YwPoint point = new LambdaQueryChainWrapper<>(ywpointMapper)
+                    .eq(YwPoint::getSerialNumber, item.getSerialNumber())
+                    .one();
+            if (Objects.isNull(point)) {
+                continue;
+            }
+            Report entity = ReportForm.getEntityByForm(form, null);
+            entity.setImportBatchNumber(pid);
+            entity.setSerialNumber(item.getSerialNumber());
+            entity.setStatus(0);
+            entity.setIdentify(IdUtils.randomNO(now));
+            entity.setCreateTime(now);
+            entity.setUpdateTime(now);
+            baseMapper.insert(entity);
+            List<ReportErrorType> errorTypeList = form.getErrorTypeList().stream().map(err -> {
+                ReportErrorType reportErrorType = new ReportErrorType();
+                reportErrorType.setErrorType(err);
+                reportErrorType.setDeleted(0);
+                reportErrorType.setCreateTime(now);
+                reportErrorType.setReportId(entity.getId());
+                return reportErrorType;
+            }).collect(Collectors.toList());
+            reportErrorTypeService.saveBatch(errorTypeList);
+            success++;
+        }
+        return Result.ok("鎶ュ鐐逛綅鏁帮細" + list.size() + "锛屽鍏ユ垚鍔熸暟锛�" + success);
+    }
+
+    @Override
+    public Result getTogether(String pid) {
+        List<Report> list = baseMapper.getTogether(pid);
+        return Result.ok().data(list);
     }
 
     /**
@@ -67,17 +182,45 @@
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Result update(ReportForm form) {
 
         Report entity = baseMapper.selectById(form.getId());
-
         // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊
         Assert.notNull(entity, "璁板綍涓嶅瓨鍦�");
-        BeanUtils.copyProperties(form, entity);
-        if (baseMapper.updateById(entity) > 0) {
-            return Result.ok("淇敼鎴愬姛");
+        Date now = new Date();
+        entity.setUpdateTime(now);
+        if ("浜嬪墠鎶ュ".equals(form.getReportType())) {
+            // 濡傛灉鏄簨鍓嶆姤澶囬渶瑕佹楠屾槸鍚﹀凡缁忕敓鎴愪笅鍙戝伐鍗�
+            YwPointVO point = ywpointMapper.countNotFinishedWorkOrderByGb(form.getPointId());
+            if (Objects.nonNull(point)) {
+                throw new RuntimeException(String.format("鐐逛綅銆�%s銆戝凡缁忓瓨鍦ㄤ笅鍙戝伐鍗曪紝鏃犳硶浜嬪墠鎶ュ", point.getPointName()));
+            }
         }
-        return Result.error("淇敼澶辫触");
+        YwPoint point = new LambdaQueryChainWrapper<>(ywpointMapper)
+                .eq(YwPoint::getSerialNumber, form.getPointId())
+                .one();
+        if (Objects.isNull(point)) {
+            throw new RuntimeException("鐐逛綅涓嶅瓨鍦�");
+        }
+        BeanUtils.copyProperties(form, entity);
+        entity.setSerialNumber(form.getPointId());
+        // 閲嶇疆涓哄緟瀹℃牳
+        entity.setStatus(0);
+        baseMapper.updateById(entity);
+        new LambdaUpdateChainWrapper<>(reportErrorTypeService.getBaseMapper())
+                .eq(ReportErrorType::getReportId, form.getId())
+                .remove();
+        List<ReportErrorType> errorTypeList = form.getErrorTypeList().stream().map(err -> {
+            ReportErrorType reportErrorType = new ReportErrorType();
+            reportErrorType.setErrorType(err);
+            reportErrorType.setDeleted(0);
+            reportErrorType.setCreateTime(now);
+            reportErrorType.setReportId(entity.getId());
+            return reportErrorType;
+        }).collect(Collectors.toList());
+        reportErrorTypeService.saveBatch(errorTypeList);
+        return Result.ok("淇敼鎴愬姛");
     }
 
     /**
@@ -113,29 +256,25 @@
      */
     @Override
     public Result page(ReportQuery query) {
-
-        IPage<Report> page = new LambdaQueryChainWrapper<>(baseMapper)
-                .eq(StringUtils.isNotBlank(query.getReportType()), Report::getReportType, query.getReportType())
-                .le(Objects.nonNull(query.getBeginCreateTime()), Report::getBeginCreateTime, query.getBeginCreateTime())
-                .ge(Objects.nonNull(query.getEndCreateTime()), Report::getEndCreateTime, query.getEndCreateTime())
-                .orderByDesc(Report::getCreateTime)
-                .page(PageUtil.getPage(query, Report.class));
-
-        List<ReportVO> vos = page.getRecords().stream()
-                .map(
-                        entity -> {
-                            ReportVO vo = ReportVO.getVoByEntity(entity, null);
-                            YwUnit unit = unitMapper.selectById(vo.getUnitId());
-                            vo.setUnitName(unit.getUnitName());
-                            YwPeople ywPeople = peopleMapper.selectById(vo.getPeopleId());
-                            vo.setPeopleName(ywPeople.getYwPersonName());
-                            Region region = regionMapper.selectById(vo.getPointId());
-                            vo.setPointName(region.getFullName());
-                            return vo;
-                        }
-                )
-                .collect(Collectors.toList());
-        return Result.ok().data(vos).total(page.getTotal());
+        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));
+        page.getRecords().stream().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));
+            }
+        });
+        return Result.ok().data(page).total(page.getTotal());
     }
 
     /**
@@ -145,10 +284,16 @@
      */
     @Override
     public Result detail(String id) {
-
         Report entity = baseMapper.selectById(id);
         Assert.notNull(entity, "璁板綍涓嶅瓨鍦�");
         ReportVO vo = ReportVO.getVoByEntity(entity, null);
+        vo.setPointId(vo.getSerialNumber());
+        List<ReportErrorType> errList = new LambdaQueryChainWrapper<>(reportErrorTypeService.getBaseMapper())
+                .select(ReportErrorType::getErrorType)
+                .eq(ReportErrorType::getReportId, id)
+                .list();
+        List<String> list = errList.stream().map(ReportErrorType::getErrorType).collect(Collectors.toList());
+        vo.setErrorTypeList(list);
         return Result.ok().data(vo);
     }
 
@@ -166,4 +311,97 @@
                 .collect(Collectors.toList());
         return Result.ok().data(vos);
     }
+
+    @Override
+    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();
+    }
+
+
+    @Override
+    public Result auditingRecord(Integer id) {
+        List<ReportVO> reportList = baseMapper.examineRecord(id);
+        return Result.ok().data(reportList);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result auditing(ReportAuditingForm form) {
+        if (CollectionUtils.isEmpty(form.getTogetherList())) {
+            form.setTogetherList(new ArrayList<>(2));
+        }
+        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(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