lyh
2025-02-17 1dcf43467f34eb70002be3c2f3cd7605ceb5dcdd
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -1,14 +1,18 @@
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.conditions.query.QueryWrapper;
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.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;
@@ -23,16 +27,12 @@
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.DncDevicePermissionMapper;
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 +93,12 @@
    @Resource
    private IMdcOverrunAlarmService mdcOverrunAlarmService;
    @Resource
    private ISysParamsService ISysParamsService;
    @Resource
    private DncDevicePermissionMapper dncDevicePermissionMapper;
    @Override
    public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) {
@@ -113,8 +119,40 @@
    @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();
        String userId = user.getId();
        DncDevicePermission dncDevicePermission=new DncDevicePermission();
        dncDevicePermission.setDeviceId(mdcEquipment.getId());
        dncDevicePermission.setUserId(userId);
        dncDevicePermissionMapper.insert(dncDevicePermission);
        //step.2 保存所属部门
        if (oConvertUtils.isNotEmpty(selectedDeparts)) {
            String[] arr = selectedDeparts.split(",");
@@ -137,6 +175,22 @@
    @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;
            }
        }
        //step.1 修改设备基础信息
        this.updateById(mdcEquipment);
        //step.2 修改部门
@@ -167,6 +221,15 @@
                mdcProductionEquipmentMapper.insert(productionEquipment);
            }
        }
        //step.4 修改设备权限
        //先删后加
        dncDevicePermissionMapper.delete(new QueryWrapper<DncDevicePermission>().lambda().eq(DncDevicePermission::getDeviceId, mdcEquipment.getId()));
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        DncDevicePermission dncDevicePermission=new DncDevicePermission();
        dncDevicePermission.setDeviceId(mdcEquipment.getId());
        dncDevicePermission.setUserId(userId);
        dncDevicePermissionMapper.insert(dncDevicePermission);
    }
    @Override
@@ -179,7 +242,8 @@
        line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getEquipmentId, id));
        // 3. 删除设备产线关系
        line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, id));
        // 4. 删除设备权限
        line += dncDevicePermissionMapper.delete(new LambdaQueryWrapper<DncDevicePermission>().eq(DncDevicePermission::getDeviceId, id));
        return line != 0;
    }
@@ -220,6 +284,8 @@
    @Override
    public void removeEquipmentForProduction(String productionId, String equipmentId) {
        mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getProductionId, productionId).eq(MdcProductionEquipment::getEquipmentId, equipmentId));
        //移除设备权限
        dncDevicePermissionMapper.delete(new LambdaQueryWrapper<DncDevicePermission>().eq(DncDevicePermission::getDeviceId, equipmentId));
    }
    @Override
@@ -260,6 +326,7 @@
            if (equipmentList != null && !equipmentList.isEmpty()) {
                for (MdcEquipment mdcEquipment : equipmentList) {
                    MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
                    tree.setParentId(mdcEquipmentTree.getKey());
                    mdcEquipmentTree.getChildren().add(tree);
                }
@@ -616,6 +683,8 @@
                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);
@@ -730,7 +799,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;
    }
    /**