Lius
2025-03-21 87874019eefbe03dd429b5b7eed49d963ef03c88
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceInfoServiceImpl.java
@@ -1,6 +1,5 @@
package org.jeecg.modules.dnc.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
@@ -12,7 +11,6 @@
import org.jeecg.modules.dnc.service.*;
import org.jeecg.modules.dnc.service.support.DeviceTreeWrapper;
import org.jeecg.modules.dnc.ucenter.UserDepartExt;
import org.jeecg.modules.dnc.utils.ValidateUtil;
import org.jeecg.modules.dnc.entity.*;
import org.jeecg.modules.mdc.entity.MdcEquipment;
@@ -20,8 +18,10 @@
import org.jeecg.modules.mdc.service.IMdcProductionEquipmentService;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.entity.MdcProductionEquipment;
import org.jeecg.modules.system.entity.MdcUserProduction;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.jeecg.modules.system.service.IMdcUserProductionService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.dnc.response.DeviceCode;
import org.jeecg.modules.dnc.response.DeviceGroupCode;
@@ -61,14 +61,13 @@
    @Lazy
    private IProductInfoService productInfoService;
    @Autowired
    private INcLogInfoService iNcLogInfoService;
    @Autowired
    private IMdcProductionService mdcProductionService;
    @Autowired
    private IMdcEquipmentService mdcEquipmentService;
    @Autowired
    private IMdcProductionEquipmentService mdcProductionEquipmentService;
    @Autowired
    private IMdcUserProductionService mdcUserProductionService;
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addDeviceInfo(DeviceInfo deviceInfo) {
@@ -97,15 +96,6 @@
        if(group == null) {
            ExceptionCast.cast(DeviceCode.DEVICE_GROUP_NONE);
        }
        //添加日志
        NcLogInfo ncLogInfo = new NcLogInfo();
        //模块
        ncLogInfo.setModuleInfo("设备结构树");
        //类型
        ncLogInfo.setOperateType(2);
        //日志内容
        ncLogInfo.setLogContent("设备名称:"+deviceInfo.getDeviceName()+",设备编号:"+deviceInfo.getDeviceNo());
        iNcLogInfoService.saveLogNcInfos(ncLogInfo);
        boolean b = super.save(deviceInfo);
        if(!b) {
            ExceptionCast.cast(DeviceCode.DEVICE_SAVE_ERROR);
@@ -148,17 +138,6 @@
            ExceptionCast.cast(DeviceCode.DEVICE_NOT_EXIST);
        deviceInfo.setDeviceId(id);
        deviceInfo.setGroupId(null);
        //添加日志
        NcLogInfo ncLogInfo = new NcLogInfo();
        //模块
        ncLogInfo.setModuleInfo("设备结构树");
        //类型
        ncLogInfo.setOperateType(3);
        //日志内容
        ncLogInfo.setLogContent("设备名称:"+deviceInfo.getDeviceName());
        //修改保存备注
        ncLogInfo.setRemark(JSONObject.toJSONString(en));
        iNcLogInfoService.saveLogNcInfos(ncLogInfo);
        return super.updateById(deviceInfo);
    }
@@ -182,15 +161,6 @@
        b = devicePermissionStreamService.deleteDepartByDeviceId(en.getGroupId(), en.getDeviceId());
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        //添加日志
        NcLogInfo ncLogInfo = new NcLogInfo();
        //模块
        ncLogInfo.setModuleInfo("设备结构树");
        //类型
        ncLogInfo.setOperateType(4);
        //日志内容
        ncLogInfo.setLogContent("设备名称:"+en.getDeviceName());
        iNcLogInfoService.saveLogNcInfos(ncLogInfo);
        return super.removeById(en.getDeviceId());
    }
@@ -225,8 +195,8 @@
            if(mdcProduction == null) {
                ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_NOT_EXIST);
            }
            DeviceGroupPermission permission = deviceGroupPermissionService.getByUserIdAndGroupId(userId, mdcProduction.getId());
            if(permission == null)
            MdcUserProduction mdcUserProduction=mdcUserProductionService.getByUserIdAndGroupId(userId,mdcProduction.getId());
            if(mdcUserProduction == null)
                return false;
            return true;
        }else if(nodeType == 2) {
@@ -243,13 +213,13 @@
    }
    @Override
    public List<UserDepartExt> getUserPermsList(Integer nodeType, String paramId) {
    public List<SysUser> getUserPermsList(Integer nodeType, String paramId) {
        if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId))
            return null;
        if(nodeType == 1) {
            return deviceGroupPermissionService.getUserPermsByGroupId(paramId);
            return mdcUserProductionService.getUserPermsByGroupId(paramId);
        }else if(nodeType == 2) {
            return devicePermissionService.getUserPermsByDeviceId(paramId);
            return mdcUserProductionService.getUserPermsByDeviceId(paramId);
        }else {
            return null;
        }
@@ -260,9 +230,9 @@
        if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId))
            return null;
        if(nodeType == 1) {
            return deviceGroupPermissionService.getUserNonPermsByGroupId(paramId);
            return mdcUserProductionService.getUserNonPermsByGroupId(paramId);
        }else if(nodeType == 2) {
            return devicePermissionService.getUserNonPermsByDeviceId(paramId);
            return mdcUserProductionService.getUserNonPermsByDeviceId(paramId);
        }else {
            return null;
        }
@@ -296,14 +266,14 @@
                ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
            }
            //获取分组下所有的子分组
            List<MdcProduction> childrenList = mdcProductionService.queryProdByPid(mdcProduction.getId());
            List<MdcProduction> childrenList = mdcProductionService.recursionChildrenByPid(mdcProduction.getId());
            List<String> childrenIds = new ArrayList<>();
            if(childrenList != null && !childrenList.isEmpty()) {
                childrenList.forEach(item -> {
                    childrenIds.add(item.getId());
                    boolean b = checkDevicePerm(1, item.getId());
                    if(b) {
                        b = deviceGroupPermissionService.assignAddUser(mdcProduction, userList);
                        b = deviceGroupPermissionService.assignAddUser(item, userList);
                        if(!b) {
                            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                        }
@@ -366,6 +336,8 @@
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean assignAddUser(MdcEquipment mdcEquipment, Collection<SysUser> userList) {
        if(mdcEquipment == null || userList == null || userList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        MdcProductionEquipment mdcProductionEquipment=mdcProductionEquipmentService
@@ -384,7 +356,7 @@
            if(stream == null) {
                stream = new DevicePermissionStream();
                stream.setUserId(item.getId());
                stream.setGroupId(mdcProductionEquipment.getId());
                stream.setGroupId(mdcProductionEquipment.getProductionId());
                stream.setDeviceId(mdcEquipment.getId());
                permissionStreamList.add(stream);
            }
@@ -486,14 +458,14 @@
                ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
            }
            //获取分组下所有的子分组
            List<MdcProduction> childrenList = mdcProductionService.queryProdByPid(mdcProduction.getId());
            List<MdcProduction> childrenList = mdcProductionService.recursionChildrenByPid(mdcProduction.getId());
            List<String> childrenIds = new ArrayList<>();
            if(childrenList != null && !childrenList.isEmpty()) {
                childrenList.forEach(item -> {
                    childrenIds.add(item.getId());
                    boolean b = checkDevicePerm(1, item.getId());
                    if(b) {
                        b = deviceGroupPermissionService.assignRemoveUser(mdcProduction, userList);
                        b = deviceGroupPermissionService.assignRemoveUser(item, userList);
                        if(!b) {
                            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                        }