From 1292cf73f7db223f35ab450eabeeedbf8802eb5a Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期四, 14 三月 2024 09:35:32 +0800
Subject: [PATCH] 首页设备状态计数接口

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java |  276 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 264 insertions(+), 12 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..1e21981 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,9 @@
 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;
@@ -35,6 +37,7 @@
 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 +76,22 @@
 
     @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) {
@@ -355,7 +374,8 @@
         mdcEquipmentDto.setDataFlag(Integer.parseInt(CommonConstant.STATUS_1));
         ControlSystem controlSystem = controlSystemService.getByDriveType(mdcEquipmentDto.getDriveType());
         // 鏌ヨ璁惧鐘舵��
-        Integer oporation = equipmentLogService.selectEquipmentOporation(mdcEquipment.getEquipmentId());
+        EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(mdcEquipment.getEquipmentId());
+        Integer oporation = equipmentLog.getOporation();
 
         if (controlSystem != null) {
             //鑾峰彇宸ヤ綔鏁版嵁骞跺垵濮嬪寲
@@ -372,6 +392,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 +413,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 +438,40 @@
                             } 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 if ("alarm".equals(englishName)) {
+                            if (oporation == 22) {
+                                value = equipmentLog.getAlarm();
+                            } else {
+                                value = "鏃�";
+                            }
+                        } 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()) {
+                                    value = mdcAlarmInfo.get(0).getAlarmContent();
+                                }
+                            } else {
+                                value = "鏃�";
+                            }
+                        } 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 +726,198 @@
         return list.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList());
     }
 
+    @Override
+    public IPage<MdcEquipment> pageList(Page<MdcEquipment> page, MdcEquipmentVo mdcEquipment, HttpServletRequest req) {
+        if (StringUtils.isNotBlank(mdcEquipment.getProductionName())) {
+            // 閫掑綊鏌ヨ鎵�鏈夊瓙鑺傜偣
+            List<String> productionIds = mdcProductionService.recursionChildren(mdcEquipment.getProductionName());
+            mdcEquipment.setProductionIds(productionIds);
+        }
+        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();
+        //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
+     * @return
+     */
+    @Override
+    public List<MdcEquipment> exportXlsList(MdcEquipmentVo mdcEquipment) {
+        if (StringUtils.isNotBlank(mdcEquipment.getProductionName())) {
+            // 閫掑綊鏌ヨ鎵�鏈夊瓙鑺傜偣
+            List<String> productionIds = mdcProductionService.recursionChildren(mdcEquipment.getProductionName());
+            mdcEquipment.setProductionIds(productionIds);
+        }
+        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<>();
+        //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d
+        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) {
+        return this.baseMapper.findWorkLineLast(tableName);
+    }
+
+    /**
+     * 璁惧杩愯鐘舵�佺粺璁�
+     */
+    @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;
+        }
+        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);
+                }
+            }
+        }
+        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;
+    }
+
 }

--
Gitblit v1.9.3