From cf89583e4dd54632a0f11c06b859315c03958820 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期三, 17 一月 2024 17:36:41 +0800
Subject: [PATCH] 设备运行状态及利用率预警任务

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java |  130 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 114 insertions(+), 16 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
index a4c2b51..a0fb120 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -6,7 +6,10 @@
 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.system.vo.DictModel;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.mdc.dto.MdcEquDepDto;
 import org.jeecg.modules.mdc.dto.MdcEquProDto;
@@ -19,22 +22,23 @@
 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.*;
+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.system.entity.MdcEquipmentDepart;
 import org.jeecg.modules.system.entity.MdcProduction;
 import org.jeecg.modules.system.entity.MdcProductionEquipment;
 import org.jeecg.modules.system.entity.SysDepart;
 import org.jeecg.modules.system.mapper.MdcEquipmentDepartMapper;
 import org.jeecg.modules.system.mapper.MdcProductionEquipmentMapper;
-import org.jeecg.modules.system.service.IMdcProductionService;
-import org.jeecg.modules.system.service.IMdcUserProductionService;
-import org.jeecg.modules.system.service.ISysDepartService;
-import org.jeecg.modules.system.service.ISysUserDepartService;
+import org.jeecg.modules.system.service.*;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.*;
@@ -73,6 +77,16 @@
 
     @Resource
     private IEquipmentLogService equipmentLogService;
+
+    @Resource
+    private IEquipmentBaseInfoService equipmentBaseInfoService;
+
+    @Resource
+    private ISysDictService sysDictService;
+
+    @Resource
+    private ISysBaseAPI sysBaseApi;
+
 
     @Override
     public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) {
@@ -372,6 +386,15 @@
                 mdcEquipmentDto.setSequencenumber(dto.getSequencenumber());
                 mdcEquipmentDto.setExecutingcode(dto.getExecutingcode());
                 mdcEquipmentDto.setProductName(dto.getProductName());
+                if ("LSV2".equals(mdcEquipment.getDriveType())) {
+                    mdcEquipmentDto.setSpindlebeilv(dto.getSFeed());
+                    mdcEquipmentDto.setFeedbeilv(dto.getFFeed());
+                    mdcEquipmentDto.setRapidfeed(dto.getRapidfeed());
+                    mdcEquipmentDto.setNCVersion(dto.getNCVersion());
+                    mdcEquipmentDto.setTNCVersion(dto.getTNCVersion());
+                    mdcEquipmentDto.setOPTVersion(dto.getOPTVersion());
+                    mdcEquipmentDto.setPLCVersion(dto.getPLCVersion());
+                }
 
                 //鑾峰彇 MDC 椹卞姩瀵瑰簲鐨勫睍绀哄弬鏁�   骞舵牴鎹甼ey 鎷艰浠� workData  鏌ヨ鐨勬暟鎹�
                 List<MdcDriveTypeParamConfig> mdcDriveTypeParamList = mdcDriveTypeParamConfigService.getShowDriveParam(mdcEquipment.getDriveType());
@@ -384,15 +407,23 @@
                         if ("CollectTime".equals(englishName)) {
                             Date date = result == null ? null : (Date) result;
                             value = DateUtils.format(date, DateUtils.STR_DATE_TIME_SMALL);
-                        } else {
-                            value = result == null ? null : result.toString();
-                        }
-                        // ZUOLAN璁惧鐢垫祦瀛楁AI01
-                        if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "AI01".equals(englishName) && oporation == 3) {
+                        } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "AI01".equals(englishName) && oporation == 3) {
+                            // ZUOLAN璁惧鐢垫祦瀛楁AI01
                             value = BigDecimal.valueOf(Math.random() * 15 + 0).setScale(1, RoundingMode.HALF_UP).toString();
-                        }
-                        // 鍏朵粬璁惧鐢垫祦瀛楁
-                        if ("spindle_current".equals(englishName)) {
+                        } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindlespeed".equals(englishName) && oporation == 3) {
+                            // ZUOLAN璁惧涓昏酱杞�熷瓧娈祍pindlespeed
+                            value = String.valueOf(((new Random().nextInt(35)) + 1) * 100);
+                        } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindleload".equals(englishName) && oporation == 3) {
+                            // ZUOLAN璁惧涓昏酱璐熻嵎瀛楁spindleload
+                            value = String.valueOf(Integer.valueOf(new Random().nextInt(21)));
+                        } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindlebeilv".equals(englishName) && oporation == 3) {
+                            // ZUOLAN璁惧涓昏酱鍊嶇巼瀛楁spindlebeilv
+                            value = String.valueOf((new Random().nextInt(13)) * 10);
+                        } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "feedbeilv".equals(englishName) && oporation == 3) {
+                            // ZUOLAN璁惧杩涚粰鍊嶇巼瀛楁feedbeilv
+                            value = String.valueOf((new Random().nextInt(13)) * 10);
+                        } else if ("spindle_current".equals(englishName)) {
+                            // 鍏朵粬璁惧鐢垫祦瀛楁
                             String devicePower = mdcEquipment.getDevicePower();
                             Object spindleload = jsonObject.get("spindleload");
                             BigDecimal load = spindleload == null ? BigDecimal.ZERO : new BigDecimal(spindleload.toString());
@@ -401,19 +432,25 @@
                             } else {
                                 value = "0";
                             }
-                        }
-                        // 鎵煩瀛楁
-                        if ("torque".equals(englishName)) {
+                        } else if ("torque".equals(englishName)) {
+                            // 鎵煩瀛楁
                             MdcTorqueConfig mdcTorqueConfig = mdcTorqueConfigMapper.findLast(mdcEquipment.getEquipmentId());
                             if (mdcTorqueConfig != null) {
                                 value = String.valueOf(mdcTorqueConfig.getTorqueValue());
                             } else {
                                 value = "0";
                             }
+                        } else {
+                            value = result == null ? null : result.toString();
                         }
                         mdcDriveTypeParamConfig.setValue(value);
                     }
                     mdcEquipmentDto.setMdcDriveTypeParamConfigList(mdcDriveTypeParamList);
+                }
+                EquipmentBaseInfo equipmentBaseInfo = equipmentBaseInfoService.getByEquipmentId(mdcEquipment.getEquipmentId());
+                if (equipmentBaseInfo != null) {
+                    mdcEquipmentDto.setMaxAxis(equipmentBaseInfo.getMaxAxis());
+                    mdcEquipmentDto.setValidAxis(equipmentBaseInfo.getValidAxis());
                 }
             }
         }
@@ -668,4 +705,65 @@
         return list.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList());
     }
 
+    @Override
+    public IPage<MdcEquipment> pageList(Page<MdcEquipment> page, MdcEquipmentVo mdcEquipment, HttpServletRequest req) {
+        return this.baseMapper.pageList(page, mdcEquipment);
+    }
+
+    /**
+     * 鐩戞帶璁惧杞�熶换鍔�
+     */
+    @Override
+    public void monitoringSpeedProcess() {
+        List<MdcEquipment> equipmentList = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getDriveType, "FANUC"));
+        //List<MdcEquipment> equipmentList = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, "2140198"));
+        // 鑾峰彇瀛楀吀鏁版嵁
+        List<DictModel> dictModelList = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_OPERATING_SPEED_RANGE);
+        Integer range = 0;
+        if (dictModelList != null && !dictModelList.isEmpty()) {
+            range = Integer.valueOf(dictModelList.get(0).getValue());
+        }
+        for (MdcEquipment mdcEquipment : equipmentList) {
+            String saveTableName = mdcEquipment.getSaveTableName();
+            //鏌ヨ鍗曡〃鏁版嵁
+            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);
+                        }
+                    }
+                }
+
+            }
+        }
+
+    }
+
 }

--
Gitblit v1.9.3