Lius
2025-08-27 37b8c9b35795ae0792086d9b3283355a212cc610
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -1,22 +1,18 @@
package org.jeecg.modules.mdc.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.mdc.dto.MdcEquDepDto;
import org.jeecg.modules.mdc.dto.MdcEquProDto;
import org.jeecg.modules.mdc.dto.MdcEquipmentDetailedDto;
import org.jeecg.modules.mdc.dto.MdcEquipmentDto;
import org.jeecg.modules.mdc.entity.*;
import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper;
import org.jeecg.modules.mdc.mapper.MdcTorqueConfigMapper;
import org.jeecg.modules.mdc.model.MdcEquipmentTree;
import org.jeecg.modules.mdc.service.*;
import org.jeecg.modules.mdc.util.DateUtils;
@@ -41,6 +37,8 @@
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -72,27 +70,15 @@
    private IEquipmentWorkLineService equipmentWorkLineService;
    @Resource
    private IMdcDriveTypeParamConfigService mdcDriveTypeParamConfigService;
    @Resource
    private MdcTorqueConfigMapper mdcTorqueConfigMapper;
    @Resource
    private IEquipmentLogService equipmentLogService;
    @Resource
    private IEquipmentBaseInfoService equipmentBaseInfoService;
    @Resource
    private ISysBaseAPI sysBaseApi;
    @Resource
    private IMdcAlarmInfoService mdcAlarmInfoService;
    @Resource
    private IMdcEquipmentThresholdService mdcEquipmentThresholdService;
    @Resource
    private IMdcOverrunAlarmService mdcOverrunAlarmService;
    @Override
    public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) {
@@ -383,8 +369,9 @@
                        Object object = mapData.get(englishName);
                        String value = "";
                        if ("CollectTime".equals(englishName)) {
                            Date date = object == null ? null : (Date) object;
                            value = DateUtils.format(date, DateUtils.STR_DATE_TIME_SMALL);
                            LocalDateTime date = object == null ? null : (LocalDateTime) object;
                            DateTimeFormatter customFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                            value = date.format(customFormatter);
                        } else if ("ZUOLAN".equals(mdcEquipmentDetailedDto.getDriveType()) && "AI01".equals(englishName) && oporation == 3) {
                            // ZUOLAN设备电流字段AI01
                            value = BigDecimal.valueOf(Math.random() * 15 + 0).setScale(1, RoundingMode.HALF_UP).toString();
@@ -407,14 +394,6 @@
                            BigDecimal load = spindleload == null ? BigDecimal.ZERO : new BigDecimal(spindleload.toString());
                            if (StringUtils.isNotEmpty(devicePower) && oporation == 3) {
                                value = new BigDecimal(devicePower).divide(new BigDecimal("380"), 2, BigDecimal.ROUND_HALF_UP).add(load).toString();
                            } else {
                                value = "0";
                            }
                        } else if ("torque".equals(englishName)) {
                            // 扭矩字段
                            MdcTorqueConfig mdcTorqueConfig = mdcTorqueConfigMapper.findLast(mdcEquipmentDetailedDto.getEquipmentId());
                            if (mdcTorqueConfig != null) {
                                value = String.valueOf(mdcTorqueConfig.getTorqueValue());
                            } else {
                                value = "0";
                            }
@@ -734,66 +713,6 @@
    }
    /**
     * 监控设备运行参数任务
     */
    @Override
    public void monitoringSpeedProcess() {
//        List<MdcEquipment> equipmentList = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getDriveType, "FANUC"));
        List<MdcEquipment> equipmentList = super.list();
        //List<MdcEquipment> equipmentList = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, "2140198"));
        for (MdcEquipment mdcEquipment : equipmentList) {
            List<MdcEquipmentThreshold> mdcEquipmentThresholdList = mdcEquipmentThresholdService.list(new LambdaQueryWrapper<MdcEquipmentThreshold>().eq(MdcEquipmentThreshold::getControlSystemType, mdcEquipment.getDriveType()));
            if (mdcEquipmentThresholdList != null && !mdcEquipmentThresholdList.isEmpty()) {
                String saveTableName = mdcEquipment.getSaveTableName();
                StringBuilder builder = new StringBuilder();
                for (MdcEquipmentThreshold mdcEquipmentThreshold : mdcEquipmentThresholdList) {
                    builder.append(",").append(mdcEquipmentThreshold.getEnglishName()).append(" as \"").append(mdcEquipmentThreshold.getEnglishName()).append("\"  ");
                }
                Map<String, Object> param = new HashMap<>();
                param.put("columns", builder.toString());
                param.put("tableName", saveTableName);
                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.setFromUser("admin");
                        messageDTO.setToUser("admin");
                        MdcOverrunAlarm mdcOverrunAlarm = new MdcOverrunAlarm();
                        mdcOverrunAlarm.setEquipmentId(mdcEquipment.getEquipmentId());
                        mdcOverrunAlarm.setSetValue(min + "-" + max);
                        mdcOverrunAlarm.setRealValue(actualValue.toString());
                        if (actualValue > max) {
                            // 高
                            messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备" + mdcEquipmentThreshold.getChineseName() + "高报警!");
                            sysBaseApi.sendSysAnnouncement(messageDTO);
                            mdcOverrunAlarm.setAlarmContent(mdcEquipmentThreshold.getChineseName() + "高报警");
                            mdcOverrunAlarmService.save(mdcOverrunAlarm);
                        } else if (actualValue < min) {
                            // 低
                            messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备" + mdcEquipmentThreshold.getChineseName() + "低报警!");
                            sysBaseApi.sendSysAnnouncement(messageDTO);
                            mdcOverrunAlarm.setAlarmContent(mdcEquipmentThreshold.getChineseName() + "低报警");
                            mdcOverrunAlarmService.save(mdcOverrunAlarm);
                        }
                    }
                }
            }
        }
    }
    /**
     * 导出list
     *
     * @param mdcEquipment
@@ -834,21 +753,6 @@
        //填充设备数据
        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