Lius
2024-06-18 1279d6eee2934b2765ce4ea1bf3a4d45d931760d
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -21,10 +21,7 @@
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.util.FindsEquipmentDepartUtil;
import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil;
import org.jeecg.modules.mdc.vo.MdcEquipmentDepVo;
import org.jeecg.modules.mdc.vo.MdcEquipmentProVo;
import org.jeecg.modules.mdc.vo.MdcEquipmentVo;
import org.jeecg.modules.mdc.vo.WorkshopEquipmentVo;
import org.jeecg.modules.mdc.vo.*;
import org.jeecg.modules.system.entity.MdcEquipmentDepart;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.entity.MdcProductionEquipment;
@@ -378,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) {
@@ -455,7 +455,7 @@
                            } else {
                                value = "无";
                            }
                        }  else if ("alarmContent".equals(englishName)) {
                        } else if ("alarmContent".equals(englishName)) {
                            if (oporation == 22) {
                                List<MdcAlarmInfo> mdcAlarmInfo = mdcAlarmInfoService.list(new LambdaQueryWrapper<MdcAlarmInfo>().eq(MdcAlarmInfo::getDriveType, mdcEquipment.getDriveType()).eq(MdcAlarmInfo::getAlarmCode, equipmentLog.getAlarm()).eq(MdcAlarmInfo::getIsUse, 0));
                                if (mdcAlarmInfo != null && !mdcAlarmInfo.isEmpty()) {
@@ -724,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());
    }
@@ -759,15 +776,20 @@
                Map<String, Object> param = new HashMap<>();
                param.put("columns", builder.toString());
                param.put("tableName", saveTableName);
                Map<String, Object> map = this.baseMapper.getWorkLineLast(param);
                if (map != null) {
                Map<String, Object> map = new HashMap<>();
                try {
                    map = this.baseMapper.getWorkLineLast(param);
                } catch (Exception e) {
                    log.error("查询单表数据出差!", e);
                }
                if (!map.isEmpty()) {
                    for (MdcEquipmentThreshold mdcEquipmentThreshold : mdcEquipmentThresholdList) {
                        Integer actualValue = Integer.valueOf(map.get(mdcEquipmentThreshold.getEnglishName()).toString());
                        Integer max = mdcEquipmentThreshold.getMaxThreshold();
                        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();
@@ -790,45 +812,6 @@
                    }
                }
            }
//            //查询单表数据
//            MdcEquipmentDto mdcEquipmentDto = this.baseMapper.getWorkLineLast(saveTableName);
//            if (mdcEquipmentDto != null) {
//                MessageDTO messageDTO = new MessageDTO();
//                messageDTO.setTitle("设备运行转速报警!");
//                messageDTO.setCategory("预警消息");
//                messageDTO.setFromUser("admin");
//                messageDTO.setToUser("admin");
//                Integer spindlespeed = Integer.valueOf(mdcEquipmentDto.getSpindlespeed());
//                Integer actualspindlespeed = Integer.valueOf(mdcEquipmentDto.getActualspindlespeed());
//                if (range.equals(0)) {
//                    if (spindlespeed > actualspindlespeed) {
//                        // 实际值大于设定值   高
//                        messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备运行转速高报警!");
//                        sysBaseApi.sendSysAnnouncement(messageDTO);
//                    } else if (spindlespeed < actualspindlespeed) {
//                        // 实际值小于设定值   低
//                        messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备运行转速低报警!");
//                        sysBaseApi.sendSysAnnouncement(messageDTO);
//                    }
//                } else {
//                    int max = actualspindlespeed + actualspindlespeed * (range / 100);
//                    int min = actualspindlespeed - actualspindlespeed * (range / 100);
//                    if (spindlespeed > max || spindlespeed < min) {
//                        if (spindlespeed > actualspindlespeed) {
//                            // 实际值大于设定值   高
//                            messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备运行转速高报警!");
//                            sysBaseApi.sendSysAnnouncement(messageDTO);
//                        } else if (spindlespeed < actualspindlespeed) {
//                            // 实际值小于设定值   低
//                            messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备运行转速低报警!");
//                            sysBaseApi.sendSysAnnouncement(messageDTO);
//                        }
//                    }
//                }
//
//            }
        }
    }
@@ -849,4 +832,68 @@
        return this.baseMapper.exportXlsList(mdcEquipment);
    }
    /**
     * 通过车间ids获取设备树
     *
     * @param ids
     * @return
     */
    @Override
    public List<MdcEquipmentTree> loadTreeListByProductionIds(String ids) {
        List<String> productionIds = Arrays.asList(ids.split(","));
        //获取所有产线数据
        List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
        List<String> allProductionIds = new ArrayList<>();
        //找到所有产线id的上级id
        if (!productionIds.isEmpty()) {
            for (String productionId : productionIds) {
                this.getAllProductionIds(productionList, productionId, allProductionIds);
            }
        }
        //过滤产线数据
        List<MdcProduction> list = productionList.stream().filter((MdcProduction mdcProduction) -> allProductionIds.contains(mdcProduction.getId())).collect(Collectors.toList());
        //组装产线设备树
        List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
        //填充设备数据
        FillEquipmentByProduction(treeList);
        return treeList;
    }
    /**
     * 查询单表数据
     * @param tableName
     * @return
     */
    @Override
    public MdcEquipmentDto getWorkLineLast(String tableName) {
        try {
            return this.baseMapper.findWorkLineLast(tableName);
        } catch (Exception e) {
            return null;
        }
    }
    @Override
    public List<String> listEquipmentIdShift(MdcEfficiencyReportShiftQueryVo 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());
    }
}