From 23855599412c4d61b38d78f0f3abd3430a48b5b1 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期三, 25 六月 2025 11:51:38 +0800
Subject: [PATCH] Merge branch 'mdc_hyjs_master'

---
 lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java | 1081 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1,081 insertions(+), 0 deletions(-)

diff --git a/lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java b/lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
new file mode 100644
index 0000000..49944e5
--- /dev/null
+++ b/lxzn-module-mdc-common/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -0,0 +1,1081 @@
+package org.jeecg.modules.mdc.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.SecurityUtils;
+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.LoginUser;
+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;
+import org.jeecg.modules.mdc.util.DncCopyEquipment;
+import org.jeecg.modules.mdc.util.FindsEquipmentDepartUtil;
+import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil;
+import org.jeecg.modules.mdc.vo.*;
+import org.jeecg.modules.system.entity.*;
+import org.jeecg.modules.system.mapper.MdcEquipmentDepartMapper;
+import org.jeecg.modules.system.mapper.MdcProductionEquipmentMapper;
+import org.jeecg.modules.system.service.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+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.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * @Description: 璁惧琛�
+ * @Author: liuS
+ * @Date: 2023-03-22
+ * @Version: V1.0
+ */
+@Slf4j
+@Service
+public class MdcEquipmentServiceImpl extends ServiceImpl<MdcEquipmentMapper, MdcEquipment> implements IMdcEquipmentService {
+
+    @Resource
+    private MdcEquipmentDepartMapper mdcEquipmentDepartMapper;
+    @Resource
+    private MdcProductionEquipmentMapper mdcProductionEquipmentMapper;
+    @Resource
+    private ISysUserDepartService sysUserDepartService;
+    @Resource
+    private IMdcUserProductionService mdcUserProductionService;
+    @Resource
+    private ISysDepartService sysDepartService;
+    @Resource
+    private IMdcProductionService mdcProductionService;
+    @Resource
+    private IEquipmentWorkLineService equipmentWorkLineService;
+    @Resource
+    private IMdcDriveTypeParamConfigService mdcDriveTypeParamConfigService;
+    @Resource
+    private MdcTorqueConfigMapper mdcTorqueConfigMapper;
+    @Resource
+    private IEquipmentLogService equipmentLogService;
+    @Resource
+    private ISysBaseAPI sysBaseApi;
+    @Resource
+    private IMdcAlarmInfoService mdcAlarmInfoService;
+
+    @Resource
+    private IMdcEquipmentThresholdService mdcEquipmentThresholdService;
+
+    @Resource
+    private IMdcOverrunAlarmService mdcOverrunAlarmService;
+
+    @Resource
+    private ISysParamsService ISysParamsService;
+
+    @Resource
+    private IDncDevicePermissionService iDncDevicePermissionService;
+
+    @Value("${fileNCPath}")
+    private String fileNCPath;
+
+    @Autowired
+    private IEquipmentService equipmentService;
+
+
+    @Override
+    public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) {
+        List<MdcEquipmentDepVo> list = this.baseMapper.getDepNamesByEquipmentIds(equipmentIds);
+        Map<String, String> res = new HashMap(5);
+        list.forEach(item -> res.merge(item.getEquipmentId(), item.getDepartName(), (a, b) -> a + "," + b));
+        return res;
+    }
+
+    @Override
+    public Map<String, String> getProNamesByEquipmentIds(List<String> equipmentIds) {
+        List<MdcEquipmentProVo> list = this.baseMapper.getProNamesByEquipmentIds(equipmentIds);
+        Map<String, String> res = new HashMap(5);
+        list.forEach(item -> res.merge(item.getEquipmentId(), item.getProductionName(), (a, b) -> a + "," + b));
+        return res;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void saveMdcEquipment(MdcEquipment mdcEquipment, String selectedDeparts, String selectedProduction) {
+        if (mdcEquipment.getSystemValue()!=null) {
+            switch (mdcEquipment.getSystemValue()){
+                case "1":
+                    mdcEquipment.setDeviceTypeDnc("1");
+                    break;
+                case "2":
+                    mdcEquipment.setDeviceTypeMdc("1");
+                    break;
+                case "3":
+                    mdcEquipment.setDeviceTypeDnc("1");
+                    mdcEquipment.setDeviceTypeMdc("1");
+                    break;
+            }
+        }else {
+            //鑾峰彇绯荤粺绫诲瀷
+            SysParams sysParams = ISysParamsService.getSysPramBySettingKey("system_type");
+            //MDC绯荤粺
+            if ("-1".equals(sysParams.getSettingValue())){
+                mdcEquipment.setDeviceTypeMdc("1");
+            }
+            //DNC绯荤粺
+            if ("1".equals(sysParams.getSettingValue())) {
+                mdcEquipment.setDeviceTypeDnc("1");
+            }
+        }
+        //step.1 淇濆瓨璁惧
+        this.save(mdcEquipment);
+        //DNC娣诲姞璁惧鏉冮檺
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        iDncDevicePermissionService.addDevicePermission(mdcEquipment.getId(), user.getId());
+        //step.2 淇濆瓨鎵�灞為儴闂�
+        if (oConvertUtils.isNotEmpty(selectedDeparts)) {
+            String[] arr = selectedDeparts.split(",");
+            for (String departId : arr) {
+                MdcEquipmentDepart equipmentDepart = new MdcEquipmentDepart(mdcEquipment.getId(), departId);
+                mdcEquipmentDepartMapper.insert(equipmentDepart);
+            }
+        }
+        //step.3 淇濆瓨鎵�灞炰骇绾�
+        if (oConvertUtils.isNotEmpty(selectedProduction)) {
+            String[] arr = selectedProduction.split(",");
+            for (String productionId : arr) {
+                MdcProductionEquipment mdcProductionEquipment = new MdcProductionEquipment(mdcEquipment.getId(), productionId);
+                mdcProductionEquipmentMapper.insert(mdcProductionEquipment);
+            }
+        }
+        //step.3 淇濆瓨璁惧瀵瑰簲鐨勪骇绾挎潈闄�
+        addDevicePermission(mdcEquipment);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    @CacheEvict(value = {"mdc:cache:encrypt:equipment"}, allEntries = true)
+    public void editMdcEquipment(MdcEquipment mdcEquipment) {
+        if (mdcEquipment.getSystemValue()!=null) {
+            switch (mdcEquipment.getSystemValue()){
+                case "1":
+                    mdcEquipment.setDeviceTypeDnc("1");
+                    mdcEquipment.setDeviceTypeMdc("0");
+                    break;
+                case "2":
+                    mdcEquipment.setDeviceTypeDnc("0");
+                    mdcEquipment.setDeviceTypeMdc("1");
+                    break;
+                case "3":
+                    mdcEquipment.setDeviceTypeDnc("1");
+                    mdcEquipment.setDeviceTypeMdc("1");
+                    break;
+            }
+        }
+        //骞崇Щ璁惧鐩綍涓嬬幇鏈夌粨鏋勪笌鏂囦欢
+        //鑾峰彇鍘熸湁缁撴瀯
+        String OldPath="";
+        String NewPath="";
+        List<String> OldStrings=mdcProductionService.findListParentTreeAll(mdcEquipment.getId());
+        if (OldStrings != null && !OldStrings.isEmpty()) {
+            OldPath = fileNCPath+"/"+StringUtils.join(OldStrings.toArray(), "/")+"/"+mdcEquipment.getEquipmentId();
+        }
+        //step.1 淇敼璁惧鍩虹淇℃伅
+        this.updateById(mdcEquipment);
+        //step.2 淇敼閮ㄩ棬
+        String departs = mdcEquipment.getSelectedDeparts();
+        String[] arr = {};
+        if (oConvertUtils.isNotEmpty(departs)) {
+            arr = departs.split(",");
+        }
+        //鍏堝垹鍚庡姞
+        mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getEquipmentId, mdcEquipment.getId()));
+        if (oConvertUtils.isNotEmpty(departs)) {
+            for (String departId : arr) {
+                MdcEquipmentDepart equipmentDepart = new MdcEquipmentDepart(mdcEquipment.getId(), departId);
+                mdcEquipmentDepartMapper.insert(equipmentDepart);
+            }
+        }
+        //鍒犻櫎鎵�鏈夎澶囨潈闄�
+        iDncDevicePermissionService.remove(new QueryWrapper<DncDevicePermission>().lambda().eq(DncDevicePermission::getDeviceId, mdcEquipment.getId()));
+        //step.3 淇敼浜х嚎
+        String productions = mdcEquipment.getSelectedProduction();
+        String[] array = {};
+        if (oConvertUtils.isNotEmpty(productions)) {
+            array = productions.split(",");
+        }
+        //鍏堝垹鍚庡姞
+        mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, mdcEquipment.getId()));
+        if (oConvertUtils.isNotEmpty(productions)) {
+            for (String productionId : array) {
+                MdcProductionEquipment productionEquipment = new MdcProductionEquipment(mdcEquipment.getId(), productionId);
+                mdcProductionEquipmentMapper.insert(productionEquipment);
+            }
+        }
+        List<String> NewStrings = mdcProductionService.findListParentTreeAll(mdcEquipment.getId());
+        if (NewStrings != null && !NewStrings.isEmpty()) {
+            NewPath = fileNCPath+"/"+StringUtils.join(NewStrings.toArray(), "/")+"/"+mdcEquipment.getEquipmentId();
+        }
+        // 骞崇ЩOldPath涓嬬殑鏂囦欢鍒癗ewPath涓�
+        DncCopyEquipment.CopyEquipmentPath(OldPath,NewPath);
+        //淇濆瓨璁惧瀵瑰簲鐨勪骇绾挎潈闄�
+        addDevicePermission(mdcEquipment);
+        //step.4 淇敼璁惧鏉冮檺
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        List<DncDevicePermission> dncDevicePermissions=iDncDevicePermissionService.list(new LambdaQueryWrapper<DncDevicePermission>()
+                .eq(DncDevicePermission::getDeviceId, mdcEquipment.getId()).eq(DncDevicePermission ::getUserId, user.getId()));
+        if (CollectionUtils.isEmpty(dncDevicePermissions)){
+            iDncDevicePermissionService.addDevicePermission(mdcEquipment.getId(), user.getId());
+        }
+    }
+
+    private void addDevicePermission(MdcEquipment mdcEquipment) {
+        List<String> productionIds=mdcProductionEquipmentMapper
+                .selectList(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, mdcEquipment.getId()))
+                .stream().map(MdcProductionEquipment::getProductionId).collect(Collectors.toList());
+        List<MdcUserProduction> mdcUserProductionList=mdcUserProductionService.queryByProductionIds(productionIds);
+        mdcUserProductionList.forEach(item->{
+            iDncDevicePermissionService.addDevicePermission(mdcEquipment.getId(), item.getUserId());
+        });
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    @CacheEvict(value = {"mdc:cache:encrypt:equipment"}, allEntries = true)
+    public boolean deleteById(String id) {
+        // 1. 鍒犻櫎璁惧
+        int line = this.baseMapper.deleteById(id);
+        // 2. 鍒犻櫎璁惧閮ㄩ棬鍏崇郴
+        line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getEquipmentId, id));
+        // 3. 鍒犻櫎璁惧浜х嚎鍏崇郴
+        line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, id));
+        // 4. 鍒犻櫎璁惧鏉冮檺
+        line += iDncDevicePermissionService.remove(new LambdaQueryWrapper<DncDevicePermission>().eq(DncDevicePermission::getDeviceId, id))? 1 : 0;
+        return line != 0;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    @CacheEvict(value = {"mdc:cache:encrypt:equipment"}, allEntries = true)
+    public boolean deleteByIds(List<String> equipmentIds) {
+        // 1. 鍒犻櫎璁惧
+        int line = this.baseMapper.deleteBatchIds(equipmentIds);
+        // 2. 鍒犻櫎璁惧閮ㄩ棬鍏崇郴
+        line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().in(MdcEquipmentDepart::getEquipmentId, equipmentIds));
+        // 3. 鍒犻櫎璁惧浜х嚎鍏崇郴
+        line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().in(MdcProductionEquipment::getEquipmentId, equipmentIds));
+
+        return line != 0;
+    }
+
+    @Override
+    public IPage<MdcEquipment> pageListByDepId(Page<MdcEquipment> page, String departId, String equipmentId) {
+        return this.baseMapper.pageListByDepId(page, departId, equipmentId);
+    }
+
+    @Override
+    public IPage<MdcEquipment> pageListByProId(Page<MdcEquipment> page, String productionId, String equipmentId) {
+        return this.baseMapper.pageListByProId(page, productionId, equipmentId);
+    }
+
+    @Override
+    public void removeEquipmentForDepart(String departId, String equipmentId) {
+        mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getDepId, departId).eq(MdcEquipmentDepart::getEquipmentId, equipmentId));
+    }
+
+    @Override
+    public void removeEquipmentsForDepart(String departId, List<String> equipmentIdList) {
+        mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getDepId, departId).in(MdcEquipmentDepart::getEquipmentId, equipmentIdList));
+    }
+
+    @Override
+    public void removeEquipmentForProduction(String productionId, String equipmentId) {
+        mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getProductionId, productionId).eq(MdcProductionEquipment::getEquipmentId, equipmentId));
+        //绉婚櫎璁惧鏉冮檺
+        iDncDevicePermissionService.remove(new LambdaQueryWrapper<DncDevicePermission>().eq(DncDevicePermission::getDeviceId, equipmentId));
+    }
+
+    @Override
+    public void removeEquipmentsForProduction(String productionId, List<String> equipmentIdList) {
+        mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getProductionId, productionId).in(MdcProductionEquipment::getEquipmentId, equipmentIdList));
+    }
+
+    @Override
+    public List<MdcEquipmentTree> loadTreeListByDepart(String userId) {
+        //鑾峰彇鎵�鏈夐儴闂ㄦ暟鎹�
+        List<SysDepart> departList = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(SysDepart::getDepartOrder));
+        //鏍规嵁鐢ㄦ埛ID鑾峰彇鎷ユ湁鐨勯儴闂╥d闆嗗悎
+        List<String> departIds = sysUserDepartService.queryDepartIdsByUserId(userId);
+        List<String> allDepartIds = new ArrayList<>();
+        //鎵惧埌鎵�鏈夐儴闂╥d鐨勪笂绾d
+        if (departIds != null && !departIds.isEmpty()) {
+            for (String departId : departIds) {
+                this.getAllDepartIds(departList, departId, allDepartIds);
+            }
+        }
+        //杩囨护閮ㄩ棬鏁版嵁
+        List<SysDepart> list = departList.stream().filter((SysDepart sysDepart) -> allDepartIds.contains(sysDepart.getId())).collect(Collectors.toList());
+        //缁勮閮ㄩ棬璁惧鏍�
+        List<MdcEquipmentTree> treeList = FindsEquipmentDepartUtil.wrapEquipmentDepartTreeList(list);
+        //濉厖璁惧鏁版嵁
+        FillEquipmentByDepart(treeList);
+        return treeList;
+    }
+
+    /**
+     * 閮ㄩ棬璁惧鏍戝~鍏呰澶囨暟鎹�
+     *
+     * @param treeList
+     */
+    private void FillEquipmentByDepart(List<MdcEquipmentTree> treeList) {
+        for (MdcEquipmentTree mdcEquipmentTree : treeList) {
+            List<MdcEquipment> equipmentList = this.baseMapper.queryByDepartId(mdcEquipmentTree.getKey());
+            if (equipmentList != null && !equipmentList.isEmpty()) {
+                for (MdcEquipment mdcEquipment : equipmentList) {
+                    MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
+
+                    tree.setParentId(mdcEquipmentTree.getKey());
+                    mdcEquipmentTree.getChildren().add(tree);
+                }
+                mdcEquipmentTree.setLeaf(false);
+            }
+            if (!mdcEquipmentTree.getChildren().isEmpty()) {
+                FillEquipmentByDepart(mdcEquipmentTree.getChildren());
+            }
+        }
+    }
+
+    /**
+     * 鑾峰彇鎵�鏈夌殑閮ㄩ棬id锛堝寘鍚墍鏈変笂绾э級
+     */
+    private void getAllDepartIds(List<SysDepart> departList, String departId, List<String> allDepartIds) {
+        if (!allDepartIds.contains(departId)) {
+            allDepartIds.add(departId);
+        }
+        for (SysDepart sysDepart : departList) {
+            if (StringUtils.isEmpty(sysDepart.getParentId())) {
+                continue;
+            }
+            if (departId.equals(sysDepart.getId())) {
+                if (!allDepartIds.contains(sysDepart.getParentId())) {
+                    allDepartIds.add(sysDepart.getParentId());
+                    getAllDepartIds(departList, sysDepart.getParentId(), allDepartIds);
+                }
+            }
+        }
+    }
+
+
+    @Override
+    public List<MdcEquipmentTree> loadTreeListByProduction(String userId) {
+        //鑾峰彇鎵�鏈変骇绾挎暟鎹�
+        List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).eq(MdcProduction::getMdcFlag, CommonConstant.DEFAULT_1).orderByAsc(MdcProduction::getProductionOrder));
+        //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚�
+        List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId);
+        List<String> allProductionIds = new ArrayList<>();
+        //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d
+        if (productionIds != null && !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;
+    }
+
+    /**
+     * 璁惧鐩戞帶鍒楄〃
+     */
+    @Override
+    public List<MdcEquipmentMonitor> queryEquipmentMonitorList(String userId, String key) {
+        List<String> equipmentIds = this.getEquipmentIdsProduction(userId, key);
+        if (equipmentIds == null || equipmentIds.isEmpty()) {
+            return Collections.emptyList();
+        }
+        List<MdcEquipmentMonitor> result = this.baseMapper.checkStatusFromEquipmentIds(equipmentIds);
+        if (result != null && !result.isEmpty()) {
+            for (MdcEquipmentMonitor mdcEquipmentMonitor : result) {
+                if (mdcEquipmentMonitor.getOporation() != null) {
+                    switch (mdcEquipmentMonitor.getOporation()) {
+                        case 1:
+                        case 2:
+                            mdcEquipmentMonitor.setOporationDict("寰呮満");
+                            break;
+                        case 3:
+                            mdcEquipmentMonitor.setOporationDict("杩愯");
+                            break;
+                        case 22:
+                            mdcEquipmentMonitor.setOporationDict("鎶ヨ");
+                            break;
+                        case 5:
+                            mdcEquipmentMonitor.setOporationDict("鏁呴殰");
+                            break;
+                        default:
+                            mdcEquipmentMonitor.setOporationDict("鍏虫満");
+                            break;
+                    }
+                } else {
+                    mdcEquipmentMonitor.setOporationDict("鍏虫満");
+                    mdcEquipmentMonitor.setOporation(0);
+                }
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 璁惧鐩戞帶 - 璁惧璇︾粏淇℃伅
+     */
+    @Override
+    public Map<String, Object> mdcEquipmentDetailedInfo(String id) {
+        Map<String, Object> result = new HashMap<>();
+        MdcEquipmentDetailedDto mdcEquipmentDetailedDto = this.baseMapper.findById(id);
+        result.put("equipment", mdcEquipmentDetailedDto);
+        // 鏌ヨ璁惧鐘舵��
+        EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(mdcEquipmentDetailedDto.getEquipmentId());
+        if (equipmentLog == null) {
+            return result;
+        }
+        Integer oporation = equipmentLog.getOporation();
+        //鑾峰彇宸ヤ綔鏁版嵁骞跺垵濮嬪寲
+        String saveTableName = mdcEquipmentDetailedDto.getSaveTableName();
+        Map<String, Object> mapData = equipmentWorkLineService.getDataList(saveTableName);
+        if (mapData != null) {
+//            Map<String, Object> runData = new LinkedHashMap<>();
+            List<Map<String, Object>> runData = new ArrayList<>();
+            //鑾峰彇 MDC 椹卞姩瀵瑰簲鐨勫睍绀哄弬鏁�   骞舵牴鎹甼ey 鎷艰浠� workData  鏌ヨ鐨勬暟鎹�
+            List<MdcDriveTypeParamConfig> mdcDriveTypeParamList = mdcDriveTypeParamConfigService.getShowDriveParam(mdcEquipmentDetailedDto.getDriveType());
+            if (mdcDriveTypeParamList != null && !mdcDriveTypeParamList.isEmpty()) {
+                for (MdcDriveTypeParamConfig mdcDriveTypeParamConfig : mdcDriveTypeParamList) {
+                    Map<String, Object> map = new LinkedHashMap<>();
+                    String englishName = mdcDriveTypeParamConfig.getEnglishName();
+                    String chineseName = mdcDriveTypeParamConfig.getChineseName();
+                    map.put("key", chineseName);
+                    if (mapData.containsKey(englishName)) {
+                        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);
+                        } 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();
+                        } else if ("ZUOLAN".equals(mdcEquipmentDetailedDto.getDriveType()) && "spindlespeed".equals(englishName) && oporation == 3) {
+                            // ZUOLAN璁惧涓昏酱杞�熷瓧娈祍pindlespeed
+                            value = String.valueOf(((new Random().nextInt(35)) + 1) * 100);
+                        } else if ("ZUOLAN".equals(mdcEquipmentDetailedDto.getDriveType()) && "spindleload".equals(englishName) && oporation == 3) {
+                            // ZUOLAN璁惧涓昏酱璐熻嵎瀛楁spindleload
+                            value = String.valueOf(Integer.valueOf(new Random().nextInt(21)));
+                        } else if ("ZUOLAN".equals(mdcEquipmentDetailedDto.getDriveType()) && "spindlebeilv".equals(englishName) && oporation == 3) {
+                            // ZUOLAN璁惧涓昏酱鍊嶇巼瀛楁spindlebeilv
+                            value = String.valueOf((new Random().nextInt(13)) * 10);
+                        } else if ("ZUOLAN".equals(mdcEquipmentDetailedDto.getDriveType()) && "feedbeilv".equals(englishName) && oporation == 3) {
+                            // ZUOLAN璁惧杩涚粰鍊嶇巼瀛楁feedbeilv
+                            value = String.valueOf((new Random().nextInt(13)) * 10);
+                        } else if ("spindle_current".equals(englishName)) {
+                            // 鍏朵粬璁惧鐢垫祦瀛楁
+                            String devicePower = mdcEquipmentDetailedDto.getDevicePower();
+                            Object spindleload = mapData.get("spindleload");
+                            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";
+                            }
+                        } 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, mdcEquipmentDetailedDto.getDriveType()).eq(MdcAlarmInfo::getAlarmCode, equipmentLog.getAlarm()).eq(MdcAlarmInfo::getIsUse, 0));
+                                if (mdcAlarmInfo != null && !mdcAlarmInfo.isEmpty()) {
+                                    value = mdcAlarmInfo.get(0).getAlarmContent();
+                                }
+                            } else {
+                                value = "鏃�";
+                            }
+                        } else {
+                            value = object == null ? "" : object.toString();
+                        }
+                        map.put("value", value);
+                        runData.add(map);
+                        if ("spindlebeilv".equals(englishName)) {
+                            result.put("spindlebeilv", value);
+                        }
+                        if ("feedbeilv".equals(englishName)) {
+                            result.put("feedbeilv", value);
+                        }
+                        if ("spindleload".equals(englishName)) {
+                            result.put("spindleload", value);
+                        }
+                        if ("rapidfeed".equals(englishName)) {
+                            result.put("rapidfeed", value);
+                        }
+                    }
+                }
+            }
+            result.put("runData", runData);
+        }
+        return result;
+    }
+
+    /**
+     * 閫氳繃鐢ㄦ埛閮ㄩ棬鍏崇郴鑾峰彇璁惧id闆嗗悎
+     */
+    @Override
+    public List<String> getEquipmentIdsByDepart(String userId, String key) {
+        //鑾峰彇鎵�鏈夐儴闂ㄦ暟鎹�
+        List<SysDepart> departList = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(SysDepart::getDepartOrder));
+        //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勯儴闂ㄤ俊鎭泦鍚�
+        List<String> departIds = sysUserDepartService.queryDepartIdsByUserId(userId);
+        List<String> allDepartIds = new ArrayList<>();
+        if (departIds != null && !departIds.isEmpty()) {
+            for (String departId : departIds) {
+                this.getAllDepartIds(departList, departId, allDepartIds);
+            }
+        }
+        //鏍规嵁浜х嚎闆嗗悎鏌ユ壘鎵�鏈夎澶噄d
+        if (allDepartIds.isEmpty()) {
+            return null;
+        }
+        List<String> equipmentIds = this.baseMapper.queryIdsByDeparts(allDepartIds);
+        if (StringUtils.isNotEmpty(key)) {
+            //key涓嶄负绌猴紝鏌ヨ鎵�鏈変笅绾ч儴闂╥d
+            List<String> partDepart = this.findAllDeparts(key);
+            partDepart.add(key);
+            //杩囨护鏃犳潈闄愰儴闂╥d
+            List<String> allDepartIdsByKey = partDepart.stream().filter(allDepartIds::contains).collect(Collectors.toList());
+            equipmentIds = this.baseMapper.queryIdsByDeparts(allDepartIdsByKey);
+        }
+        return equipmentIds;
+    }
+
+    /**
+     * 鏍规嵁鐖剁骇id閫掑綊鏌ヨ鎵�鏈変笅绾d闆嗗悎
+     */
+    private List<String> findAllDeparts(String key) {
+        List<String> departs = new ArrayList<>();
+        List<SysDepart> sysDeparts = sysDepartService.queryDeptByPid(key);
+        if (sysDeparts != null && !sysDeparts.isEmpty()) {
+            List<String> ids = sysDeparts.stream().map(SysDepart::getId).collect(Collectors.toList());
+            departs.addAll(ids);
+            for (SysDepart sysDepart : sysDeparts) {
+                List<String> allDeparts = findAllDeparts(sysDepart.getId());
+                departs.addAll(allDeparts);
+            }
+        }
+        return departs;
+    }
+
+    /**
+     * 閫氳繃鐢ㄦ埛浜х嚎鍏崇郴鑾峰彇璁惧id闆嗗悎
+     */
+    @Override
+    public List<String> getEquipmentIdsProduction(String userId, String key) {
+        //鑾峰彇鎵�鏈変骇绾挎暟鎹�
+        List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
+        //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚�
+        List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId);
+        List<String> allProductionIds = new ArrayList<>();
+        //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d
+        if (productionIds != null && !productionIds.isEmpty()) {
+            for (String productionId : productionIds) {
+                this.getAllProductionIds(productionList, productionId, allProductionIds);
+            }
+        }
+        //鏍规嵁浜х嚎闆嗗悎鏌ユ壘鎵�鏈夎澶噄d
+        if (allProductionIds.isEmpty()) {
+            return null;
+        }
+        List<String> equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIds);
+        if (StringUtils.isNotEmpty(key)) {
+            //key涓嶄负绌猴紝鏌ヨ鎵�鏈変笅绾т骇绾縤d
+            List<String> partProduction = this.findAllProductions(key);
+            partProduction.add(key);
+            //杩囨护鏃犳潈闄愪骇绾縤d
+            List<String> allProductionIdsByKey = partProduction.stream().filter(allProductionIds::contains).collect(Collectors.toList());
+            equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIdsByKey);
+        }
+        return equipmentIds;
+    }
+
+    /**
+     * 鏍规嵁璁惧id鏌ヨ璁惧鍚嶇О
+     */
+    @Override
+    public MdcEquipment findEquipmentNameByEquipmentId(String equipmentId) {
+        return this.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, equipmentId));
+    }
+
+    /**
+     * 閫夋嫨璁惧鍒嗛〉鍒楄〃
+     */
+    @Override
+    public IPage<MdcEquipment> findEquipmentList(Page<MdcEquipment> page, String userId, MdcEquipmentVo mdcEquipment) {
+        List<String> equipmentIdsByDepart = new ArrayList<>();
+        if (StringUtils.isNotEmpty(mdcEquipment.getDepartId())) {
+            equipmentIdsByDepart = getEquipmentIdsByDepart(userId, mdcEquipment.getDepartId());
+        }
+        List<String> equipmentIdsProduction = new ArrayList<>();
+        if (StringUtils.isNotEmpty(mdcEquipment.getProductionId())) {
+            equipmentIdsProduction = getEquipmentIdsProduction(userId, mdcEquipment.getProductionId());
+        }
+        List<String> allEquipments = new ArrayList<>();
+        if (StringUtils.isEmpty(mdcEquipment.getDepartId()) && StringUtils.isEmpty(mdcEquipment.getProductionId())) {
+            List<String> idsByDepart = getEquipmentIdsByDepart(userId, null);
+            List<String> idsProduction = getEquipmentIdsProduction(userId, null);
+            // 鍘婚噸骞堕泦
+            allEquipments = Stream.of(idsByDepart, idsProduction).flatMap(Collection::stream).distinct().collect(Collectors.toList());
+        }
+        if (StringUtils.isNotEmpty(mdcEquipment.getDepartId()) && StringUtils.isNotEmpty(mdcEquipment.getProductionId())) {
+            // 浜ら泦
+            allEquipments = equipmentIdsByDepart.stream().filter(equipmentIdsProduction::contains).collect(Collectors.toList());
+        }
+        LambdaQueryWrapper<MdcEquipment> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.isNotNull(MdcEquipment::getEquipmentId);
+        if (StringUtils.isNotEmpty(mdcEquipment.getEquipmentId())) {
+            queryWrapper.like(MdcEquipment::getEquipmentId, mdcEquipment.getEquipmentId());
+        }
+        if (StringUtils.isNotEmpty(mdcEquipment.getEquipmentName())) {
+            queryWrapper.like(MdcEquipment::getEquipmentName, mdcEquipment.getEquipmentName());
+        }
+        if (!allEquipments.isEmpty()) {
+            queryWrapper.in(MdcEquipment::getEquipmentId, allEquipments);
+        } else if (!equipmentIdsByDepart.isEmpty() && equipmentIdsProduction.isEmpty()) {
+            queryWrapper.in(MdcEquipment::getEquipmentId, equipmentIdsByDepart);
+        } else if (equipmentIdsByDepart.isEmpty() && !equipmentIdsProduction.isEmpty()) {
+            queryWrapper.in(MdcEquipment::getEquipmentId, equipmentIdsProduction);
+        }
+        queryWrapper.orderByAsc(MdcEquipment::getEquipmentName);
+        return this.baseMapper.selectPage(page, queryWrapper);
+    }
+
+    /**
+     * 鏍规嵁鐖剁骇id閫掑綊鏌ヨ鎵�鏈変笅绾d闆嗗悎
+     */
+    private List<String> findAllProductions(String key) {
+        List<String> productions = new ArrayList<>();
+        List<MdcProduction> mdcProductions = mdcProductionService.queryProdByPid(key);
+        if (mdcProductions != null && !mdcProductions.isEmpty()) {
+            List<String> ids = mdcProductions.stream().map(MdcProduction::getId).collect(Collectors.toList());
+            productions.addAll(ids);
+            for (MdcProduction mdcProduction : mdcProductions) {
+                List<String> allProductions = findAllProductions(mdcProduction.getId());
+                productions.addAll(allProductions);
+            }
+        }
+        return productions;
+    }
+
+    /**
+     * 浜х嚎璁惧鏍戝~鍏呰澶囨暟鎹�
+     */
+    private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList) {
+        for (MdcEquipmentTree mdcEquipmentTree : treeList) {
+            List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey());
+            if (equipmentList != null && !equipmentList.isEmpty()) {
+                for (MdcEquipment mdcEquipment : equipmentList) {
+                    MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
+                    tree.setParentId(mdcEquipmentTree.getKey());
+                    tree.setEntity(mdcEquipment);
+                    tree.setType(2);
+                    mdcEquipmentTree.getChildren().add(tree);
+                }
+                mdcEquipmentTree.setLeaf(false);
+            }
+            if (!mdcEquipmentTree.getChildren().isEmpty()) {
+                FillEquipmentByProduction(mdcEquipmentTree.getChildren());
+            }
+        }
+    }
+
+    /**
+     * 鑾峰彇鎵�鏈夌殑浜х嚎id锛堝寘鍚墍鏈変笂绾э級
+     */
+    private void getAllProductionIds(List<MdcProduction> productionList, String productionId, List<String> allProductionIds) {
+        if (!allProductionIds.contains(productionId)) {
+            allProductionIds.add(productionId);
+        }
+        for (MdcProduction mdcProduction : productionList) {
+            if (StringUtils.isEmpty(mdcProduction.getParentId())) {
+                continue;
+            }
+            if (productionId.equals(mdcProduction.getId())) {
+                if (!allProductionIds.contains(mdcProduction.getParentId())) {
+                    allProductionIds.add(mdcProduction.getParentId());
+                    getAllProductionIds(productionList, mdcProduction.getParentId(), allProductionIds);
+                }
+            }
+        }
+    }
+
+    /**
+     * 鏍规嵁浜х嚎灞傜骇鏌ヨ璁惧鍗曚釜
+     */
+    @Override
+    public MdcEquipment getEquipmentByPid(String pid, String userId) {
+        List<String> idsProduction = this.getEquipmentIdsProduction(userId, pid);
+        if (idsProduction != null && !idsProduction.isEmpty()) {
+            return super.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, idsProduction.get(0)));
+        }
+        return null;
+    }
+
+    /**
+     * 鏍规嵁璁惧缂栧彿鏌ヨ璁惧淇℃伅鍜岄儴闂ㄤ俊鎭�
+     *
+     * @param equipmentIdList
+     * @return
+     */
+    @Override
+    public List<MdcEquDepDto> findEquDepList(List<String> equipmentIdList) {
+        return this.baseMapper.findEquDepList(equipmentIdList);
+    }
+
+    /**
+     * 鏍规嵁璁惧缂栧彿鏌ヨ璁惧淇℃伅鍜屼骇绾夸俊鎭�
+     *
+     * @param equipmentIdList
+     * @return
+     */
+    @Override
+    public List<MdcEquProDto> findEquProList(List<String> equipmentIdList) {
+        return this.baseMapper.findEquProList(equipmentIdList);
+    }
+
+    /**
+     * 鏍规嵁閮ㄩ棬灞傜骇鏌ヨ璁惧鍗曚釜
+     */
+    @Override
+    public MdcEquipment getEquipmentByDepPid(String pid, String userId) {
+        List<String> idsByDepart = this.getEquipmentIdsByDepart(userId, pid);
+        if (idsByDepart != null && !idsByDepart.isEmpty()) {
+            return super.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, idsByDepart.get(0)));
+        }
+        return null;
+    }
+
+    /**
+     * 鏍规嵁澶у睆杞﹂棿id鏌ヨ璁惧鍒楄〃
+     */
+    @Override
+    public IPage<MdcEquipment> getEquipmentByWorkshopId(Page<MdcEquipment> page, WorkshopEquipmentVo workshopEquipmentVo) {
+        return this.baseMapper.getEquipmentByWorkshopId(page, workshopEquipmentVo);
+    }
+
+    @Override
+    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());
+    }
+
+    @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);
+        }
+        IPage<MdcEquipment> equipmentIPage= this.baseMapper.pageList(page, mdcEquipment);
+        equipmentIPage.getRecords().forEach(item->{
+            if (("1").equals(item.getDeviceTypeDnc())&&("1").equals(item.getDeviceTypeMdc())){
+                item.setSystemValue("3");
+            }else {
+                if (("1").equals(item.getDeviceTypeDnc())){
+                    item.setSystemValue("1");
+                }
+                if (("1").equals(item.getDeviceTypeMdc())){
+                    item.setSystemValue("2");
+                }
+            }
+        });
+        return equipmentIPage;
+    }
+
+    /**
+     * 鐩戞帶璁惧杩愯鍙傛暟浠诲姟
+     */
+    @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) {
+        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());
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void addNewEquipmentFromEam(MdcEquipment mdcEquipment, String productionId) {
+        //榛樿绯荤粺绫诲瀷
+        mdcEquipment.setSystemValue("3");
+        //鍒ゆ柇MDC鏄惁宸叉坊鍔犳璁惧
+        MdcEquipment entity = this.getBaseMapper().selectOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, mdcEquipment.getEquipmentId()));
+        if (entity != null) {
+            //MDC宸茬粡瀛樺湪姝よ澶�
+            log.warn("MDC宸茬粡瀛樺湪姝よ澶�, equipmentId={}", mdcEquipment.getEquipmentId());
+            return;
+        }
+        Equipment equipment = equipmentService.getOne(new LambdaQueryWrapper<Equipment>().eq(Equipment::getEquipmentid, mdcEquipment.getEquipmentId()));
+        if(equipment == null) {
+            //閲囬泦鏈厤缃�
+            log.warn("閲囬泦鏈厤缃�, equipmentId={}", mdcEquipment.getEquipmentId());
+            return;
+        }
+        //璁剧疆鍊�
+        mdcEquipment.setEquipmentIp(equipment.getEquipmentip());
+        mdcEquipment.setEquipmentModel(equipment.getEquipmentmodel());
+        mdcEquipment.setDataPort(equipment.getDataport());
+        mdcEquipment.setDriveType(equipment.getDrivetype());
+        mdcEquipment.setControlSystem(equipment.getControlsystem());
+        mdcEquipment.setSaveTableName(equipment.getSavetablename());
+        mdcEquipment.setEquipmentStatus(CommonConstant.STATUS_NORMAL);
+
+        this.saveMdcEquipment(mdcEquipment, null, productionId);
+    }
+
+    /**
+     * 鏍规嵁浜х嚎id闆嗗悎鏌ヨ璁惧鍒楄〃
+     * @param mdcProductionIds
+     * @return
+     */
+    @Override
+    public List<MdcEquipment> findByProductionIds(List<String> mdcProductionIds) {
+        return this.baseMapper.findByProductionIds(mdcProductionIds);
+    }
+
+    /**
+     * 鏍规嵁浜х嚎id闆嗗悎鍜岄厤閫佸皬缁勬煡璇㈣澶囧垪琛�
+     * @param mdcProductionIds
+     * @param teamCodeList
+     * @return
+     */
+    @Override
+    public List<MdcEquipment> findByProIdsAndTeamCode(List<String> mdcProductionIds, List<String> teamCodeList) {
+        return this.baseMapper.findByProIdsAndTeamCode(mdcProductionIds, teamCodeList);
+    }
+
+    /**
+     * 鏍规嵁浜х嚎id闆嗗悎鍜岃澶囩被鍨嬫煡璇㈣澶囧垪琛�
+     * @param allProductionIds
+     * @param typeList
+     * @return
+     */
+    @Override
+    public List<MdcEquipment> findByProIdsAndType(List<String> allProductionIds, List<String> typeList) {
+        return this.baseMapper.findByProIdsAndType(allProductionIds, typeList);
+    }
+
+    @Override
+    public List<MdcEquipment> getEquipmentList() {
+
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        String userId = user.getId();
+        if (StringUtils.isNotEmpty(user.getEquipmentIds())) {
+            return this.baseMapper.selectList(new LambdaQueryWrapper<MdcEquipment>().in(MdcEquipment::getEquipmentId, Arrays.asList(user.getEquipmentIds().split(StringPool.COMMA))));
+        }
+        //鑾峰彇鎵�鏈変骇绾挎暟鎹�
+        List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
+        //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚�
+        List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId);
+        List<String> allProductionIds = new ArrayList<>();
+        //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d
+        if (productionIds != null && !productionIds.isEmpty()) {
+            for (String productionId : productionIds) {
+                this.getAllProductionIds(productionList, productionId, allProductionIds);
+            }
+        }
+        //鏍规嵁浜х嚎闆嗗悎鏌ユ壘鎵�鏈夎澶噄d
+        if (allProductionIds.isEmpty()) {
+            return null;
+        }
+        List<MdcEquipment> equipmentIds = this.baseMapper.getEquipmentList(allProductionIds);
+        return equipmentIds;
+    }
+
+    @Override
+    public List<String> getEquIdsByProIds(List<String> proIds) {
+        return this.baseMapper.getEquIdsByProIds(proIds);
+    }
+
+}

--
Gitblit v1.9.3