Kaynağa Gözat

QHSE数据权限

Zimo 1 hafta önce
ebeveyn
işleme
b8cb3e881b

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/config/PmsDataPermissionConfiguration.java

@@ -24,6 +24,7 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.cert.QhseCertPersonDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.hazard.IotHazardDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.measure.IotMeasureBookDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.measure.IotMeasureDetectDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.ptw.QhsePtwDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.device.YfIotDeviceDO;
 import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
@@ -74,6 +75,7 @@ public class PmsDataPermissionConfiguration {
 //            rule.addUserColumn(SupplierDO.class);
             rule.addUserColumn(AdminUserDO.class, "id");
             rule.addDeptColumn(QhseCertPersonDO.class, "dept_id");
+            rule.addDeptColumn(QhsePtwDO.class, "dept_id");
 //            rule.addUserColumn(SupplierDO.class, "creator");
 
         };

+ 97 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/qhse/QhseStatController.java

@@ -0,0 +1,97 @@
+package cn.iocoder.yudao.module.pms.controller.admin.qhse;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
+import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.accident.vo.IotAccidentReportPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.cert.vo.IotMeasureCertPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.hazard.vo.IotHazardPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.qhse.ptw.vo.QhsePtwPageReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.cert.IotMeasureCertDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.hazard.IotHazardDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.ptw.QhsePtwDO;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.accident.IotAccidentReportMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.cert.IotMeasureCertMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.danger.IotDangerSourceMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.hazard.IotHazardMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.measure.IotMeasureBookMapper;
+import cn.iocoder.yudao.module.pms.dal.mysql.qhse.ptw.QhsePtwMapper;
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
+import com.google.common.collect.ImmutableMap;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.time.LocalDateTime;
+import java.util.*;
+
+@Tag(name = "QHSE统计分析")
+@RestController
+@RequestMapping("/rq/qhse/stat")
+@Validated
+public class QhseStatController {
+
+
+    private final IotDangerSourceMapper iotDangerSourceMapper;
+    private final IotHazardMapper iotHazardMapper;
+    private final DeptService deptService;
+    private final QhsePtwMapper qhsePtwMapper;
+    private final IotMeasureBookMapper iotMeasureBookMapper;
+    private final IotMeasureCertMapper iotMeasureCertMapper;
+    private final IotAccidentReportMapper iotAccidentReportMapper;
+
+    public QhseStatController(IotDangerSourceMapper iotDangerSourceMapper, IotDangerSourceMapper iotDangerSourceMapper1, IotHazardMapper iotHazardMapper, DeptService deptService, QhsePtwMapper qhsePtwMapper, IotMeasureBookMapper iotMeasureBookMapper, IotMeasureCertMapper iotMeasureCertMapper, IotAccidentReportMapper iotAccidentReportMapper) {
+        this.iotDangerSourceMapper = iotDangerSourceMapper1;
+        this.iotHazardMapper = iotHazardMapper;
+        this.deptService = deptService;
+        this.qhsePtwMapper = qhsePtwMapper;
+        this.iotMeasureBookMapper = iotMeasureBookMapper;
+        this.iotMeasureCertMapper = iotMeasureCertMapper;
+        this.iotAccidentReportMapper = iotAccidentReportMapper;
+    }
+
+    @GetMapping("/number")
+    public CommonResult<ImmutableMap> getStatNumber() {
+        Long danger = iotDangerSourceMapper.selectCount();
+        LocalDateTime monthBegin = LocalDateTimeUtils.getMonth();
+        IotHazardPageReqVO pageReqVO = new IotHazardPageReqVO();
+        Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
+        Set<Long> ids = new HashSet<>();
+        if (Objects.nonNull(pageReqVO.getDeptId())) {
+            ids = deptService.getChildDeptIdListFromCache(loginUserDeptId);
+            ids.add(loginUserDeptId);
+        }
+        pageReqVO.setCreateTime(new LocalDateTime[]{monthBegin, LocalDateTime.now()});
+        List<IotHazardDO> iotHazardDOS = iotHazardMapper.selectListByDept(pageReqVO, ids);
+        int monthHazard = iotHazardDOS.size();
+
+
+        IotHazardPageReqVO reqVO = new IotHazardPageReqVO();
+        List<IotHazardDO> dos = iotHazardMapper.selectListByDept(reqVO, ids);
+        int total = dos.size();
+        reqVO.setStatus("todo");
+        int todoSize = iotHazardMapper.selectListByDept(reqVO, ids).size();
+
+        QhsePtwPageReqVO qhsePtwPageReqVO = new QhsePtwPageReqVO();
+        qhsePtwPageReqVO.setCreateTime(new LocalDateTime[]{monthBegin, LocalDateTime.now()});
+        List<QhsePtwDO> qhsePtwDOS = qhsePtwMapper.selectListByDept(qhsePtwPageReqVO, ids);
+        int ptwCount = qhsePtwDOS.size();
+
+        IotMeasureCertPageReqVO iotMeasureCertPageReqVO = new IotMeasureCertPageReqVO();
+        List<IotMeasureCertDO> iotMeasureCertDOS = iotMeasureCertMapper.selectListByDept(iotMeasureCertPageReqVO, ids);
+        int totalCert = iotMeasureCertDOS.size();
+        long expiredCount = iotMeasureCertDOS.stream().filter(IotMeasureCertDO::getExpired).count();
+        long warnCount = iotMeasureCertDOS.stream().filter(e -> !e.getExpired() && e.getAlertWarn()).count();
+
+        DateTime beforeYear = DateUtil.offsetYear(new Date(), -1);
+        IotAccidentReportPageReqVO iotAccidentReportPageReqVO = new IotAccidentReportPageReqVO();
+        iotAccidentReportPageReqVO.setCreateTime(new LocalDateTime[]{monthBegin, LocalDateTime.now()});
+        int accidentSize = iotAccidentReportMapper.selectListByDept(iotAccidentReportPageReqVO, ids).size();
+        return CommonResult.success(ImmutableMap.of("danger", danger, "monthHazard", monthHazard, "totalHazard", total, "todoHazard", todoSize, "ptwCount", ptwCount,
+                "totdalCert", totalCert,"expiredCert", expiredCount,"warnCert", warnCount, "accident", accidentSize));
+    }
+}

+ 8 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/qhse/accident/IotAccidentReportMapper.java

@@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.accident.IotAccidentRepor
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -80,4 +81,11 @@ public interface IotAccidentReportMapper extends BaseMapperX<IotAccidentReportDO
 
         return selectPage(reqVO, queryWrapperX);
     }
+
+    default List<IotAccidentReportDO> selectListByDept(IotAccidentReportPageReqVO reqVO, Set<Long> ids) {
+        return selectList(new LambdaQueryWrapperX<IotAccidentReportDO>()
+                .eq(IotAccidentReportDO::getDeleted, false)
+                .betweenIfPresent(IotAccidentReportDO::getCreateTime, reqVO.getCreateTime())
+                .inIfPresent(IotAccidentReportDO::getDeptId, ids));
+    }
 }

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/qhse/hazard/IotHazardMapper.java

@@ -37,6 +37,7 @@ public interface IotHazardMapper extends BaseMapperX<IotHazardDO> {
         return selectList(new LambdaQueryWrapperX<IotHazardDO>()
                 .eqIfPresent(IotHazardDO::getStatus, reqVO.getStatus())
                 .eq(IotHazardDO::getDeleted, false)
+                .betweenIfPresent(IotHazardDO::getCreateTime, reqVO.getCreateTime())
                 .inIfPresent(IotHazardDO::getDeptId, ids));
     }
 }

+ 7 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/qhse/ptw/QhsePtwMapper.java

@@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.qhse.ptw.vo.QhsePtwPageReqVO
 import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.ptw.QhsePtwDO;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -38,4 +39,10 @@ public interface QhsePtwMapper extends BaseMapperX<QhsePtwDO> {
                 .orderByDesc(QhsePtwDO::getId));
     }
 
+    default List<QhsePtwDO> selectListByDept(QhsePtwPageReqVO reqVO, Set<Long> ids) {
+        return selectList(new LambdaQueryWrapperX<QhsePtwDO>()
+                .eq(QhsePtwDO::getDeleted, false)
+                .betweenIfPresent(QhsePtwDO::getCreateTime, reqVO.getCreateTime())
+                .inIfPresent(QhsePtwDO::getDeptId, ids));
+    }
 }