lyh
2025-02-11 009c2bcdb77a5963a639fcaa5bfd96e068db5546
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -1,5 +1,6 @@
package org.jeecg.modules.mdc.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -23,16 +24,11 @@
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.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.entity.*;
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.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -93,6 +89,9 @@
    @Resource
    private IMdcOverrunAlarmService mdcOverrunAlarmService;
    @Resource
    private ISysParamsService ISysParamsService;
    @Override
    public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) {
@@ -113,6 +112,31 @@
    @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);
        //step.2 保存所属部门
@@ -260,6 +284,7 @@
            if (equipmentList != null && !equipmentList.isEmpty()) {
                for (MdcEquipment mdcEquipment : equipmentList) {
                    MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
                    tree.setParentId(mdcEquipmentTree.getKey());
                    mdcEquipmentTree.getChildren().add(tree);
                }
@@ -293,7 +318,7 @@
    @Override
    public List<MdcEquipmentTree> loadTreeListByProduction(String userId) {
    public List<MdcEquipmentTree> loadTreeListByProduction(String userId,String type) {
        //获取所有产线数据
        List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
        //根据用户id获取拥有的产线信息集合
@@ -310,7 +335,7 @@
        //组装产线设备树
        List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
        //填充设备数据
        FillEquipmentByProduction(treeList);
        FillEquipmentByProduction(treeList,type);
        return treeList;
    }
@@ -609,19 +634,21 @@
    /**
     * 产线设备树填充设备数据
     */
    private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList) {
    private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList,String type) {
        for (MdcEquipmentTree mdcEquipmentTree : treeList) {
            List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey());
            List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey(),type);
            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());
                FillEquipmentByProduction(mdcEquipmentTree.getChildren(),type);
            }
        }
    }
@@ -730,7 +757,20 @@
            List<String> productionIds = mdcProductionService.recursionChildren(mdcEquipment.getProductionName());
            mdcEquipment.setProductionIds(productionIds);
        }
        return this.baseMapper.pageList(page, mdcEquipment);
        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;
    }
    /**
@@ -816,7 +856,7 @@
     * @return
     */
    @Override
    public List<MdcEquipmentTree> loadTreeListByProductionIds(String ids) {
    public List<MdcEquipmentTree> loadTreeListByProductionIds(String ids,String type) {
        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));
@@ -832,7 +872,7 @@
        //组装产线设备树
        List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
        //填充设备数据
        FillEquipmentByProduction(treeList);
        FillEquipmentByProduction(treeList,type);
        return treeList;
    }