Преглед на файлове

soc卡片统计及定时任务

Zimo преди 1 ден
родител
ревизия
d74bb25980

+ 42 - 16
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/qhse/soc/IotSocSummaryController.java

@@ -18,9 +18,11 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.soc.IotSocSourceDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.soc.IotSocSummaryDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.qhse.soc.IotSocSourceMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.qhse.soc.IotSocSummaryMapper;
+import cn.iocoder.yudao.module.pms.service.qhse.soc.IotSocSourceService;
 import cn.iocoder.yudao.module.pms.service.qhse.soc.IotSocSummaryService;
 import cn.iocoder.yudao.module.pms.util.SafetyObservationCardGenerator;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -59,6 +61,8 @@ public class IotSocSummaryController {
     private IotSocSummaryMapper iotSocSummaryMapper;
     @Autowired
     private DeptService deptService;
+    @Autowired
+    private IotSocSourceService iotSocSourceService;
 
     @PostMapping("/create")
     @Operation(summary = "创建SOC卡汇总")
@@ -218,29 +222,20 @@ public class IotSocSummaryController {
             ids = new HashSet<>();
         }
         List<ImmutableMap> results = new ArrayList<>();
-        Map person = new HashMap();
+//        Map person = new HashMap();
         list.stream().filter(e -> "不安全".equals(e.getName())).findFirst().ifPresent(e -> {
             List<IotSocSourceDO> summaryDOS = iotSocSourceMapper.selectList("parent_id", e.getId());
             AtomicReference<Long> unsafe = new AtomicReference<>(0L);
             summaryDOS.forEach(item -> {
+                List<String> collect = iotSocSourceService.getChildSocSourceList(ImmutableList.of(item.getId())).stream().map(gg -> String.valueOf(gg.getId())).collect(Collectors.toList());
+                collect.add(String.valueOf(item.getId()));
                 IotSocSummaryPageReqVO pageReqVO1 = new IotSocSummaryPageReqVO();
-                pageReqVO1.setSocClass(String.valueOf(item.getId()));
+//                pageReqVO1.setSocClass(String.valueOf(item.getId()));
+                pageReqVO1.setSocClasses(collect);
                 pageReqVO1.setObservationDate(pageReqVO.getObservationDate());
                 Long count = iotSocSummaryMapper.selectCountBySocClassAndTime(pageReqVO1, ids);
-                results.add(ImmutableMap.of(item.getName(), count));
+                results.add(ImmutableMap.of(item.getName(), count,"id", item.getId()));
                 unsafe.set(unsafe.get() + count);
-
-                List<IotSocSourceDO> childIds = iotSocSourceMapper.selectList("parent_id", item.getId());
-                List<ImmutableMap> countList = new ArrayList<>();
-                childIds.forEach(child -> {
-                    IotSocSummaryPageReqVO pageReqVO2 = new IotSocSummaryPageReqVO();
-                    pageReqVO2.setSocClass(String.valueOf(child.getId()));
-                    pageReqVO2.setObservationDate(pageReqVO.getObservationDate());
-                    Long childCount = iotSocSummaryMapper.selectCountBySocClassAndTime(pageReqVO2, ids);
-                    countList.add(ImmutableMap.of(child.getName(), childCount));
-                });
-                person.put(item.getName(), countList);
-
             });
             results.add(ImmutableMap.of("不安全", unsafe.get()));
         });
@@ -252,7 +247,38 @@ public class IotSocSummaryController {
             results.add(ImmutableMap.of(e.getName(), count));
         });
 
-        return success(ImmutableMap.of("total", results, "child", person));
+        return success(ImmutableMap.of("total", results));
+    }
+
+    @GetMapping("/stat/child")
+    @PermitAll
+    public CommonResult<ImmutableMap> statSocChild(IotSocSummaryPageReqVO pageReqVO) {
+        List<IotSocSourceDO> list = iotSocSourceMapper.selectList();
+        Long deptId = pageReqVO.getDeptId();
+        if (Objects.isNull(pageReqVO.getDeptId())) {
+            deptId = SecurityFrameworkUtils.getLoginUserDeptId();
+        }
+        Set<Long> ids;
+        if (Objects.nonNull(deptId)) {
+            ids = deptService.getChildDeptIdListFromCache(deptId);
+            ids.add(pageReqVO.getDeptId());
+        } else {
+            ids = new HashSet<>();
+        }
+        List<ImmutableMap> results = new ArrayList<>();
+            List<IotSocSourceDO> summaryDOS = iotSocSourceMapper.selectList("parent_id", pageReqVO.getSocClass());
+            summaryDOS.forEach(item -> {
+                List<String> collect = iotSocSourceService.getChildSocSourceList(ImmutableList.of(item.getId())).stream().map(gg -> String.valueOf(gg.getId())).collect(Collectors.toList());
+                collect.add(String.valueOf(item.getId()));
+                IotSocSummaryPageReqVO pageReqVO1 = new IotSocSummaryPageReqVO();
+//                pageReqVO1.setSocClass(String.valueOf(item.getId()));
+                pageReqVO1.setSocClasses(collect);
+                pageReqVO1.setObservationDate(pageReqVO.getObservationDate());
+                Long count = iotSocSummaryMapper.selectCountBySocClassAndTime(pageReqVO1, ids);
+                results.add(ImmutableMap.of(item.getName(), count));
+            });
+
+        return success(ImmutableMap.of("total", results));
     }
 
 }

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/qhse/soc/vo/IotSocSummaryPageReqVO.java

@@ -8,6 +8,7 @@ import lombok.ToString;
 import org.springframework.format.annotation.DateTimeFormat;
 
 import java.time.LocalDateTime;
+import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 
@@ -46,6 +47,8 @@ public class IotSocSummaryPageReqVO extends PageParam {
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime[] createTime;
 
+    private List<String> socClasses;
+
     @Schema(description = "队伍名称", example = "王五")
     private String deptName;
 

+ 4 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotDeviceMapper.java

@@ -7,8 +7,6 @@ import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainWorkOrderPageReqVO;
-import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
-import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.AllOrderResp;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotCarDevicePlateVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
@@ -249,6 +247,10 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
                 .eqIfPresent(IotDeviceDO::getBomSyncStatus, reqVO.getBomSyncStatus())
                 .eqIfPresent(IotDeviceDO::getIfInline, reqVO.getIfInline())
                 .isNotNull(IotDeviceDO::getIfInline)
+                .eq(reqVO.getSource() != null && "gateway".equals(reqVO.getSource()),
+                        IotDeviceDO::getVehicleName, null)  // gateway → 为空
+                .ne(reqVO.getSource() != null && "zhbd".equals(reqVO.getSource()),
+                        IotDeviceDO::getVehicleName, null)  // 非 gateway → 不为空
                 .orderByAsc(IotDeviceDO::getIfInline).orderByDesc(IotDeviceDO::getLastInlineTime).orderByAsc(IotDeviceDO::getDeviceCode));
     }
 

+ 4 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/qhse/soc/IotSocSourceMapper.java

@@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.qhse.soc.vo.IotSocSourcePage
 import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.soc.IotSocSourceDO;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -16,7 +17,9 @@ import java.util.List;
  */
 @Mapper
 public interface IotSocSourceMapper extends BaseMapperX<IotSocSourceDO> {
-
+    default List<IotSocSourceDO> selectListByParentId(Collection<Long> parentIds) {
+        return selectList(IotSocSourceDO::getParentId, parentIds);
+    }
     default PageResult<IotSocSourceDO> selectPage(IotSocSourcePageReqVO reqVO) {
         return selectPage(reqVO, new LambdaQueryWrapperX<IotSocSourceDO>()
                 .eqIfPresent(IotSocSourceDO::getParentId, reqVO.getParentId())

+ 3 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/qhse/soc/IotSocSummaryMapper.java

@@ -35,8 +35,9 @@ public interface IotSocSummaryMapper extends BaseMapperX<IotSocSummaryDO> {
 
     default Long selectCountBySocClassAndTime(IotSocSummaryPageReqVO reqVO, Set<Long> ids) {
         return selectCount(new LambdaQueryWrapperX<IotSocSummaryDO>()
-                .eqIfPresent(IotSocSummaryDO::getSocClass, reqVO.getSocClass())
-                .betweenIfPresent(IotSocSummaryDO::getObservationDate, reqVO.getCreateTime()));
+                .inIfPresent(IotSocSummaryDO::getDeptId, ids)
+                .inIfPresent(IotSocSummaryDO::getSocClass, reqVO.getSocClasses())
+                .betweenIfPresent(IotSocSummaryDO::getObservationDate, reqVO.getObservationDate()));
     }
 
 }

+ 4 - 4
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/qhse/BookAndCertWeekJob.java

@@ -88,7 +88,7 @@ public class BookAndCertWeekJob implements JobHandler {
                 //给项目部的角色为QHSE项目部的人员发送消息,项目部的过期及预警都要发送消息
                 userListByDeptId.stream().filter(e -> userIds.contains(e.getId())).forEach(adminUser -> {
 //                    pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
-                    pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, 140L, "13255461093");
+                    pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+"过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, 140L, "13255461093");
                 });
                 //发送给各公司的QHSE负责人
                 String companyCode = deptUtil.getCompanyCode(dept.getId());
@@ -99,7 +99,7 @@ public class BookAndCertWeekJob implements JobHandler {
                         String nickname = adminUser.getNickname();
                         if (StringUtils.isNotBlank(nickname)) {
                             if ("翟纪全".equals(nickname)||"刘学刚".equals(nickname)) {
-                                pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
+                                pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+"过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
                             }
                         }
 //                        pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, 140L, "13255461093");
@@ -111,7 +111,7 @@ public class BookAndCertWeekJob implements JobHandler {
                         String nickname = adminUser.getNickname();
                         if (StringUtils.isNotBlank(nickname)) {
                             if ("李东斌".equals(nickname)||"李强".equals(nickname)) {
-                                pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
+                                pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+"过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
                             }
                         }
 //                        pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, 140L, "13255461093");
@@ -123,7 +123,7 @@ public class BookAndCertWeekJob implements JobHandler {
                         String nickname = adminUser.getNickname();
                         if (StringUtils.isNotBlank(nickname)) {
                             if ("曲猛".equals(nickname)||"陈习荣".equals(nickname)) {
-                                pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
+                                pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+"过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, adminUser.getId(), adminUser.getMobile());
                             }
                         }
 //                        pmsMessage.sendMessage(dept.getId(), dept.getName()+"计量器具台账90天预警数量为:"+warn+",过期数量为:"+expired+"。资质证书60天预警数量为:"+warnCert+",过期数量为:"+expiredCert+"。请登录QHSE系统进行查看。", PmsConstants.WEEK_ALARM_MESSAGE, 140L, "13255461093");

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/qhse/soc/IotSocSourceService.java

@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.qhse.soc.vo.IotSocSourceSave
 import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.soc.IotSocSourceDO;
 
 import javax.validation.Valid;
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -14,6 +15,7 @@ import java.util.List;
  * @author 超级管理员
  */
 public interface IotSocSourceService {
+    List<IotSocSourceDO> getChildSocSourceList(Collection<Long> ids);
     List<IotSocSourceDO> getSocList(IotSocSourcePageReqVO pageReqVO);
     /**
      * 创建SOC卡分析数据源

+ 21 - 3
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/qhse/soc/IotSocSourceServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.pms.service.qhse.soc;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.iocoder.yudao.framework.common.exception.ErrorCode;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -15,11 +16,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
 
 /**
@@ -152,4 +152,22 @@ public class IotSocSourceServiceImpl implements IotSocSourceService {
         }
     }
 
+    @Override
+    public List<IotSocSourceDO> getChildSocSourceList(Collection<Long> ids) {
+        List<IotSocSourceDO> children = new LinkedList<>();
+        // 遍历每一层
+        Collection<Long> parentIds = ids;
+        for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环
+            // 查询当前层,所有的子产品分类
+            List<IotSocSourceDO> depts = iotSocSourceMapper.selectListByParentId(parentIds);
+            // 1. 如果没有子产品分类,则结束遍历
+            if (CollUtil.isEmpty(depts)) {
+                break;
+            }
+            // 2. 如果有子产品分类,继续遍历
+            children.addAll(depts);
+            parentIds = convertSet(depts, IotSocSourceDO::getId);
+        }
+        return children;
+    }
 }