Lius
2024-09-13 15a20a91316b726f45ccc9e06bbd632f10eedb43
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -227,7 +227,7 @@
    }
    @Override
    public List<MdcEquipmentTree> loadTreeListByDepart(String userId) {
    public List<MdcEquipmentTree> loadTreeListByDepart(String userId, String key) {
        //获取所有部门数据
        List<SysDepart> departList = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(SysDepart::getDepartOrder));
        //根据用户ID获取拥有的部门id集合
@@ -244,7 +244,7 @@
        //组装部门设备树
        List<MdcEquipmentTree> treeList = FindsEquipmentDepartUtil.wrapEquipmentDepartTreeList(list);
        //填充设备数据
        FillEquipmentByDepart(treeList);
        FillEquipmentByDepart(treeList, key);
        return treeList;
    }
@@ -253,9 +253,9 @@
     *
     * @param treeList
     */
    private void FillEquipmentByDepart(List<MdcEquipmentTree> treeList) {
    private void FillEquipmentByDepart(List<MdcEquipmentTree> treeList, String key) {
        for (MdcEquipmentTree mdcEquipmentTree : treeList) {
            List<MdcEquipment> equipmentList = this.baseMapper.queryByDepartId(mdcEquipmentTree.getKey());
            List<MdcEquipment> equipmentList = this.baseMapper.queryByDepartId(mdcEquipmentTree.getKey(), key);
            if (equipmentList != null && !equipmentList.isEmpty()) {
                for (MdcEquipment mdcEquipment : equipmentList) {
                    MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
@@ -265,7 +265,7 @@
                mdcEquipmentTree.setLeaf(false);
            }
            if (!mdcEquipmentTree.getChildren().isEmpty()) {
                FillEquipmentByDepart(mdcEquipmentTree.getChildren());
                FillEquipmentByDepart(mdcEquipmentTree.getChildren(), key);
            }
        }
    }
@@ -292,7 +292,7 @@
    @Override
    public List<MdcEquipmentTree> loadTreeListByProduction(String userId) {
    public List<MdcEquipmentTree> loadTreeListByProduction(String userId, String key) {
        //获取所有产线数据
        List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
        //根据用户id获取拥有的产线信息集合
@@ -309,7 +309,7 @@
        //组装产线设备树
        List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
        //填充设备数据
        FillEquipmentByProduction(treeList);
        FillEquipmentByProduction(treeList, key);
        return treeList;
    }
@@ -375,6 +375,9 @@
        ControlSystem controlSystem = controlSystemService.getByDriveType(mdcEquipmentDto.getDriveType());
        // 查询设备状态
        EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(mdcEquipment.getEquipmentId());
        if (equipmentLog == null) {
            return mdcEquipmentDto;
        }
        Integer oporation = equipmentLog.getOporation();
        if (controlSystem != null) {
@@ -629,9 +632,9 @@
    /**
     * 产线设备树填充设备数据
     */
    private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList) {
    private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList, String key) {
        for (MdcEquipmentTree mdcEquipmentTree : treeList) {
            List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey());
            List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey(), key);
            if (equipmentList != null && !equipmentList.isEmpty()) {
                for (MdcEquipment mdcEquipment : equipmentList) {
                    MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
@@ -641,7 +644,7 @@
                mdcEquipmentTree.setLeaf(false);
            }
            if (!mdcEquipmentTree.getChildren().isEmpty()) {
                FillEquipmentByProduction(mdcEquipmentTree.getChildren());
                FillEquipmentByProduction(mdcEquipmentTree.getChildren(), key);
            }
        }
    }
@@ -721,8 +724,25 @@
    }
    @Override
    public List<String> listEquipmentId(String equipmentType, List<String> equipmentIdList) {
        List<MdcEquipment> list = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentType, equipmentType).in(MdcEquipment::getEquipmentId, equipmentIdList));
    public List<String> listEquipmentId(MdcEfficiencyReportQueryVo vo) {
        LambdaQueryWrapper<MdcEquipment> queryWrapper = new LambdaQueryWrapper<>();
        if (vo.getEquipmentIdList() != null && !vo.getEquipmentIdList().isEmpty()) {
            queryWrapper.in(MdcEquipment::getEquipmentId, vo.getEquipmentIdList());
        }
        if (StringUtils.isNotEmpty(vo.getEquipmentType())) {
            queryWrapper.in(MdcEquipment::getEquipmentType, Arrays.asList(vo.getEquipmentType().split(",")));
        }
        if (StringUtils.isNotEmpty(vo.getDeviceLevel())) {
            queryWrapper.in(MdcEquipment::getDeviceLevel, Arrays.asList(vo.getDeviceLevel().split(",")));
        }
        if (StringUtils.isNotEmpty(vo.getDriveType())) {
            queryWrapper.in(MdcEquipment::getDriveType, Arrays.asList(vo.getDriveType().split(",")));
        }
        if (StringUtils.isNotEmpty(vo.getDeviceCategory())) {
            queryWrapper.in(MdcEquipment::getDeviceCategory, Arrays.asList(vo.getDeviceCategory().split(",")));
        }
        List<MdcEquipment> list = super.list(queryWrapper);
//        List<MdcEquipment> list = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentType, equipmentType).in(MdcEquipment::getEquipmentId, equipmentIdList));
        return list.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList());
    }
@@ -769,7 +789,7 @@
                        Integer min = mdcEquipmentThreshold.getMinThreshold();
                        MessageDTO messageDTO = new MessageDTO();
                        messageDTO.setTitle("设备" + mdcEquipmentThreshold.getChineseName() + "报警!");
                        messageDTO.setCategory("预警消息");
                        messageDTO.setCategory(CommonConstant.MSG_CATEGORY_2);
                        messageDTO.setFromUser("admin");
                        messageDTO.setToUser("admin");
                        MdcOverrunAlarm mdcOverrunAlarm = new MdcOverrunAlarm();
@@ -835,89 +855,46 @@
        //组装产线设备树
        List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
        //填充设备数据
        FillEquipmentByProduction(treeList);
        FillEquipmentByProduction(treeList, null);
        return treeList;
    }
    /**
     * 查询单表数据
     *
     * @param tableName
     * @return
     */
    @Override
    public MdcEquipmentDto getWorkLineLast(String tableName) {
        return this.baseMapper.findWorkLineLast(tableName);
        try {
            return this.baseMapper.findWorkLineLast(tableName);
        } catch (Exception e) {
            return null;
        }
    }
    /**
     * 设备运行状态统计
     */
    @Override
    public List<MdcCommonVo> getEquipmentStatusStatistics(String userId, String key) {
        List<MdcCommonVo> result = new ArrayList<>();
        MdcCommonVo mdcCommonVo1 = new MdcCommonVo();
        mdcCommonVo1.setName("关机");
        mdcCommonVo1.setValue(0);
        result.add(mdcCommonVo1);
        MdcCommonVo mdcCommonVo2 = new MdcCommonVo();
        mdcCommonVo2.setName("报警");
        mdcCommonVo2.setValue(0);
        result.add(mdcCommonVo2);
        MdcCommonVo mdcCommonVo3 = new MdcCommonVo();
        mdcCommonVo3.setName("待机");
        mdcCommonVo3.setValue(0);
        result.add(mdcCommonVo3);
        MdcCommonVo mdcCommonVo4 = new MdcCommonVo();
        mdcCommonVo4.setName("运行");
        mdcCommonVo4.setValue(0);
        result.add(mdcCommonVo4);
        MdcEquipmentStatusVo mdcEquipmentStatusVo = new MdcEquipmentStatusVo();
        List<String> equipmentIdList = this.getEquipmentIdsProduction(userId, key);
        if (equipmentIdList == null || equipmentIdList.isEmpty()) {
            return result;
    public List<String> listEquipmentIdShift(MdcEfficiencyReportShiftQueryVo vo) {
        LambdaQueryWrapper<MdcEquipment> queryWrapper = new LambdaQueryWrapper<>();
        if (vo.getEquipmentIdList() != null && !vo.getEquipmentIdList().isEmpty()) {
            queryWrapper.in(MdcEquipment::getEquipmentId, vo.getEquipmentIdList());
        }
        List<EquipmentLog> logList = this.baseMapper.getEquipmentStatusList(equipmentIdList);
        if (logList != null && !logList.isEmpty()) {
            for (EquipmentLog equipmentLog : logList) {
                if (equipmentLog.getOporation() != null) {
                    switch (equipmentLog.getOporation()) {
                        case 1:
                        case 2:
                            mdcEquipmentStatusVo.setWaitCount(mdcEquipmentStatusVo.getWaitCount() + 1);
                            break;
                        case 3:
                            mdcEquipmentStatusVo.setRunCount(mdcEquipmentStatusVo.getRunCount() + 1);
                            break;
                        case 22:
                            mdcEquipmentStatusVo.setAlarmCount(mdcEquipmentStatusVo.getAlarmCount() + 1);
                            break;
                        default:
                            mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1);
                            break;
                    }
                } else {
                    mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1);
                }
            }
        if (StringUtils.isNotEmpty(vo.getEquipmentType())) {
            queryWrapper.in(MdcEquipment::getEquipmentType, Arrays.asList(vo.getEquipmentType().split(",")));
        }
        result.clear();
        MdcCommonVo mdcCommonVo5 = new MdcCommonVo();
        mdcCommonVo5.setName("关机");
        mdcCommonVo5.setValue(mdcEquipmentStatusVo.getCloseCount());
        result.add(mdcCommonVo5);
        MdcCommonVo mdcCommonVo6 = new MdcCommonVo();
        mdcCommonVo6.setName("报警");
        mdcCommonVo6.setValue(mdcEquipmentStatusVo.getAlarmCount());
        result.add(mdcCommonVo6);
        MdcCommonVo mdcCommonVo7 = new MdcCommonVo();
        mdcCommonVo7.setName("待机");
        mdcCommonVo7.setValue(mdcEquipmentStatusVo.getWaitCount());
        result.add(mdcCommonVo7);
        MdcCommonVo mdcCommonVo8 = new MdcCommonVo();
        mdcCommonVo8.setName("运行");
        mdcCommonVo8.setValue(mdcEquipmentStatusVo.getRunCount());
        result.add(mdcCommonVo8);
        return result;
        if (StringUtils.isNotEmpty(vo.getDeviceLevel())) {
            queryWrapper.in(MdcEquipment::getDeviceLevel, Arrays.asList(vo.getDeviceLevel().split(",")));
        }
        if (StringUtils.isNotEmpty(vo.getDriveType())) {
            queryWrapper.in(MdcEquipment::getDriveType, Arrays.asList(vo.getDriveType().split(",")));
        }
        if (StringUtils.isNotEmpty(vo.getDeviceCategory())) {
            queryWrapper.in(MdcEquipment::getDeviceCategory, Arrays.asList(vo.getDeviceCategory().split(",")));
        }
        List<MdcEquipment> list = super.list(queryWrapper);
//        List<MdcEquipment> list = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentType, equipmentType).in(MdcEquipment::getEquipmentId, equipmentIdList));
        return list.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList());
    }
}