lyh
2025-02-17 1dcf43467f34eb70002be3c2f3cd7605ceb5dcdd
设备权限与车间权限
已重命名1个文件
已添加1个文件
已修改17个文件
已删除3个文件
553 ■■■■ 文件已修改
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/controller/DeviceInfoController.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/IDeviceInfoService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/IDevicePermissionService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceGroupPermissionServiceImpl.java 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceInfoServiceImpl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DevicePermissionServiceImpl.java 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/DncDevicePermissionMapper.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/entity/DncDeviceGroupPermission.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/entity/DncDevicePermission.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/DncDeviceGroupPermissionMapper.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/DncDevicePermissionMapper.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/MdcUserProductionMapper.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/MdcUserProductionMapper.xml 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/IMdcUserProductionService.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/MdcProductionServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/MdcUserProductionServiceImpl.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/controller/DeviceInfoController.java
@@ -3,9 +3,14 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.dnc.response.*;
import org.jeecg.modules.dnc.service.IDevicePermissionService;
import org.jeecg.modules.mdc.model.MdcEquipmentTree;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.dnc.entity.DeviceInfo;
import org.jeecg.modules.dnc.service.IDeviceInfoService;
@@ -23,6 +28,8 @@
public class DeviceInfoController extends JeecgController<DeviceInfo, IDeviceInfoService> {
    @Autowired
    private IDeviceInfoService deviceInfoService;
    @Autowired
    private IDevicePermissionService devicePermissionService;
    @AutoLog(value = "设备表-新增设备")
    @ApiOperation(value = "设备表-新增设备", notes = "设备表-新增设备")
@@ -70,8 +77,8 @@
    @AutoLog(value = "设备表-获取节点已分配的用户")
    @ApiOperation(value = "设备表-获取节点已分配的用户", notes = "设备表-获取节点已分配的用户")
    @GetMapping("/get/perm/user/{nodeType}/{paramId}")
    public QueryListResponseResult<UserDepartExt> getUserPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
        List<UserDepartExt> list = deviceInfoService.getUserPermsList(nodeType, paramId);
    public QueryListResponseResult<SysUser> getUserPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
        List<SysUser> list = deviceInfoService.getUserPermsList(nodeType, paramId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, list);
@@ -156,4 +163,24 @@
        }
        return new ResponseResult(CommonCode.SUCCESS);
    }
    /**
     * åŠ è½½äº§çº¿è®¾å¤‡æ ‘
     */
    @AutoLog(value = "设备表-加载产线设备树")
    @ApiOperation(value = "设备表-加载产线设备树", notes = "设备表-加载产线设备树")
    @GetMapping(value = "/queryTreeListByProduction")
    public Result<List<MdcEquipmentTree>> queryTreeListByProduction() {
        Result<List<MdcEquipmentTree>> result = new Result<>();
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        try {
            List<MdcEquipmentTree> mdcEquipmentTreeList = devicePermissionService.DncLoadTreeListByProduction(userId);
            result.setSuccess(true);
            result.setResult(mdcEquipmentTreeList);
        } catch (Exception e) {
            return Result.error("加载产线设备树失败!" + e.getMessage());
        }
        return result;
    }
}
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/IDeviceInfoService.java
@@ -61,7 +61,7 @@
     * @param paramId
     * @return
     */
    List<UserDepartExt> getUserPermsList(Integer nodeType, String paramId);
    List<SysUser> getUserPermsList(Integer nodeType, String paramId);
    /**
     * èŽ·å–èŠ‚ç‚¹æœªåˆ†é…çš„ç”¨æˆ·
     * @param nodeType
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/IDevicePermissionService.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.dnc.entity.DevicePermission;
import org.jeecg.modules.dnc.ucenter.UserDepartExt;
import org.jeecg.modules.mdc.model.MdcEquipmentTree;
import org.jeecg.modules.system.entity.SysUser;
import java.util.List;
@@ -50,4 +51,10 @@
     * @return
     */
    List<DevicePermission> getByDeviceId(String deviceId);
    /**
     * åŠ è½½äº§çº¿è®¾å¤‡æ ‘
     */
    List<MdcEquipmentTree> DncLoadTreeListByProduction(String userId);
}
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceGroupPermissionServiceImpl.java
@@ -15,8 +15,10 @@
import org.jeecg.modules.dnc.ucenter.UserDepartExt;
import org.jeecg.modules.dnc.utils.ValidateUtil;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.entity.MdcUserProduction;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.dnc.service.IDeviceGroupPermissionService;
import org.jeecg.modules.system.service.IMdcUserProductionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -35,6 +37,8 @@
    @Autowired
    @Lazy
    private IDevicePermissionStreamService devicePermissionStreamService;
    @Autowired
    private IMdcUserProductionService mdcUserProductionService;
    @Override
    public List<UserDepartExt> getUserPermsByGroupId(String groupId) {
@@ -92,15 +96,13 @@
    public boolean assignAddUser(MdcProduction mdcProduction, Collection<SysUser> userList) {
        if(mdcProduction == null || userList == null || userList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<DeviceGroupPermission> permissionList = new ArrayList<>();
        List<MdcUserProduction> mdcUserProductions=new ArrayList<>();
        List<DevicePermissionStream> permissionStreamList = new ArrayList<>();
        userList.forEach(item -> {
            DeviceGroupPermission en = groupPermissionService.getByUserIdAndGroupId(item.getId(), mdcProduction.getId());
            MdcUserProduction en = mdcUserProductionService.getByUserIdAndGroupId(item.getId(), mdcProduction.getId());
            if(en == null) {
                en = new DeviceGroupPermission();
                en.setUserId(item.getId());
                en.setGroupId(mdcProduction.getId());
                permissionList.add(en);
                en = new MdcUserProduction(item.getId(),mdcProduction.getId());
                mdcUserProductions.add(en);
            }
            DevicePermissionStream stream = devicePermissionStreamService.getByGroupIdAndUserId(mdcProduction.getId(), item.getId());
            if(stream == null) {
@@ -110,8 +112,8 @@
                permissionStreamList.add(stream);
            }
        });
        if(!permissionList.isEmpty()) {
            boolean b = groupPermissionService.saveBatch(permissionList);
        if(!mdcUserProductions.isEmpty()) {
            boolean b = mdcUserProductionService.saveBatch(mdcUserProductions);
            if(!b) {
                ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
            }
@@ -130,12 +132,12 @@
    public boolean assignRemoveUser(MdcProduction mdcProduction, Collection<SysUser> userList) {
        if(mdcProduction == null || userList == null || userList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<DeviceGroupPermission> permissionList = new ArrayList<>();
        List<MdcUserProduction> mdcUserProductions=new ArrayList<>();
        List<DevicePermissionStream> permissionStreamList = new ArrayList<>();
        userList.forEach(item -> {
            DeviceGroupPermission en = groupPermissionService.getByUserIdAndGroupId(item.getId(), mdcProduction.getId());
            MdcUserProduction en = mdcUserProductionService.getByUserIdAndGroupId(item.getId(), mdcProduction.getId());
            if(en != null) {
                permissionList.add(en);
                mdcUserProductions.add(en);
            }
            DevicePermissionStream stream = devicePermissionStreamService.getByGroupIdAndUserId(mdcProduction.getId(), item.getId());
            if(stream != null) {
@@ -143,11 +145,11 @@
            }
        });
        //校验清空设备分组权限操作
        List<DeviceGroupPermission> existList = groupPermissionService.getByGroupId(mdcProduction.getId());
        if(existList.size() <= permissionList.size())
        List<MdcUserProduction> existList = mdcUserProductionService.list(new QueryWrapper<MdcUserProduction>().eq("pro_id",mdcProduction.getId()));
        if(existList.size() <= mdcUserProductions.size())
            ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_USER_NONE);
        if(!permissionList.isEmpty()) {
            boolean b = groupPermissionService.removeByCollection(permissionList);
        if(!mdcUserProductions.isEmpty()) {
            boolean b = mdcUserProductionService.removeByCollection(mdcUserProductions);
            if(!b) {
                ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
            }
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceInfoServiceImpl.java
@@ -22,6 +22,7 @@
import org.jeecg.modules.system.entity.MdcProductionEquipment;
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;
@@ -68,7 +69,8 @@
    private IMdcEquipmentService mdcEquipmentService;
    @Autowired
    private IMdcProductionEquipmentService mdcProductionEquipmentService;
    @Autowired
    private IMdcUserProductionService mdcUserProductionService;
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addDeviceInfo(DeviceInfo deviceInfo) {
@@ -243,13 +245,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 +262,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;
        }
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DevicePermissionServiceImpl.java
@@ -1,23 +1,42 @@
package org.jeecg.modules.dnc.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.dnc.entity.DevicePermission;
import org.jeecg.modules.dnc.mapper.DevicePermissionMapper;
import org.jeecg.modules.dnc.ucenter.UserDepartExt;
import org.jeecg.modules.dnc.utils.ValidateUtil;
import org.jeecg.modules.mdc.entity.MdcEquipment;
import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper;
import org.jeecg.modules.mdc.model.MdcEquipmentTree;
import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.dnc.service.IDevicePermissionService;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.jeecg.modules.system.service.IMdcUserProductionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class DevicePermissionServiceImpl extends ServiceImpl<DevicePermissionMapper, DevicePermission> implements IDevicePermissionService {
    @Resource
    private IMdcProductionService mdcProductionService;
    @Resource
    private IMdcUserProductionService mdcUserProductionService;
    @Resource
    private MdcEquipmentMapper mdcEquipmentMapper;
    @Override
    public DevicePermission getByUserIdAndDeviceId(String userId, String deviceId) {
        if(!ValidateUtil.validateString(userId) || !ValidateUtil.validateString(deviceId))
@@ -67,4 +86,77 @@
            list = Collections.emptyList();
        return list;
    }
    /**
     * åŠ è½½äº§çº¿è®¾å¤‡æ ‘
     */
    @Override
    public List<MdcEquipmentTree> DncLoadTreeListByProduction(String userId){
        //获取所有产线数据
        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<>();
        //找到所有产线id的上级id
        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,userId);
        return treeList;
    }
    /**
     * èŽ·å–æ‰€æœ‰çš„äº§çº¿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);
                }
            }
        }
    }
    /**
     * äº§çº¿è®¾å¤‡æ ‘填充设备数据
     */
    private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList,String userId) {
        //获取已分配权限设备数据
        List<String> deviceIds=super.list(new QueryWrapper<DevicePermission>().eq("user_id",userId)).stream().map(DevicePermission::getDeviceId).collect(Collectors.toList());
        if (!deviceIds.isEmpty()){
            for (MdcEquipmentTree mdcEquipmentTree : treeList) {
                List<MdcEquipment> equipmentList = mdcEquipmentMapper.queryByProductionIdAndType(mdcEquipmentTree.getKey(),deviceIds);
                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(),userId);
                }
            }
        }
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java
@@ -405,12 +405,12 @@
    @AutoLog(value = "设备表-加载产线设备树")
    @ApiOperation(value = "设备表-加载产线设备树", notes = "设备表-加载产线设备树")
    @GetMapping(value = "/queryTreeListByProduction")
    public Result<List<MdcEquipmentTree>> queryTreeListByProduction(String type) {
    public Result<List<MdcEquipmentTree>> queryTreeListByProduction() {
        Result<List<MdcEquipmentTree>> result = new Result<>();
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        try {
            List<MdcEquipmentTree> mdcEquipmentTreeList = mdcEquipmentService.loadTreeListByProduction(userId,type);
            List<MdcEquipmentTree> mdcEquipmentTreeList = mdcEquipmentService.loadTreeListByProduction(userId);
            result.setSuccess(true);
            result.setResult(mdcEquipmentTreeList);
        } catch (Exception e) {
@@ -530,10 +530,10 @@
    @AutoLog(value = "设备表-通过车间ids获取设备树")
    @ApiOperation(value = "设备表-通过车间ids获取设备树", notes = "设备表-通过车间ids获取设备树")
    @GetMapping(value = "/loadTreeListByProductionIds")
    public Result<?> loadTreeListByProductionIds(@RequestParam(name = "ids", required = true) String ids,@RequestParam(name = "type", required = true)String type) {
    public Result<?> loadTreeListByProductionIds(@RequestParam(name = "ids", required = true) String ids) {
        Result<List<MdcEquipmentTree>> result = new Result<>();
        try {
            List<MdcEquipmentTree> mdcEquipmentTreeList = mdcEquipmentService.loadTreeListByProductionIds(ids,type);
            List<MdcEquipmentTree> mdcEquipmentTreeList = mdcEquipmentService.loadTreeListByProductionIds(ids);
            result.setSuccess(true);
            result.setResult(mdcEquipmentTreeList);
        } catch (Exception e) {
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/DncDevicePermissionMapper.java
ÎļþÒÑɾ³ý
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/MdcEquipmentMapper.java
@@ -56,7 +56,12 @@
    /**
     * æ ¹æ®äº§çº¿id查询设备
     */
    List<MdcEquipment> queryByProductionId(@Param("productionId") String productionId,@Param("type")String type);
    List<MdcEquipment> queryByProductionId(@Param("productionId") String productionId);
    /**
     * æ ¹æ®äº§çº¿id、type、已分配权限数据 æŸ¥è¯¢è®¾å¤‡
     */
    List<MdcEquipment> queryByProductionIdAndType(@Param("productionId") String productionId, @Param("deviceIds") List<String> deviceIds);
    /**
     * æŸ¥æ‰¾è®¾å¤‡ç›‘控信息
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcEquipmentMapper.xml
@@ -71,12 +71,7 @@
        WHERE
            mpe.equipment_id = me.id
            AND mpe.production_id = #{ productionId }
        <if test="type == 'DNC'">
            AND me.device_type_dnc = '1'
        </if>
        <if test="type == 'MDC'">
            AND me.device_type_mdc = '1'
        </if>
        ORDER BY me.equipment_id
    </select>
@@ -281,5 +276,23 @@
        WHERE
            t1.id = #{ id }
    </select>
    <select id="queryByProductionIdAndType" resultType="org.jeecg.modules.mdc.entity.MdcEquipment">
        SELECT
        me.*
        FROM
        mdc_production_equipment mpe,
        mdc_equipment me
        WHERE
        mpe.equipment_id = me.id
        AND mpe.production_id = #{ productionId }
        AND me.device_type_dnc = '1'
        <if test="deviceIds != null and deviceIds.size() > 0">
            AND me.id IN
            <foreach collection = "deviceIds" item = "id" index = "index" open = "(" close= ")" separator = ",">
                #{id}
            </foreach>
        </if>
        ORDER BY me.equipment_id
    </select>
</mapper>
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcEquipmentService.java
@@ -106,7 +106,7 @@
    /**
     * åŠ è½½äº§çº¿è®¾å¤‡æ ‘
     */
    List<MdcEquipmentTree> loadTreeListByProduction(String userId,String type);
    List<MdcEquipmentTree> loadTreeListByProduction(String userId);
    /**
     * è®¾å¤‡ç›‘控列表
@@ -198,7 +198,7 @@
     * @param ids
     * @return
     */
    List<MdcEquipmentTree> loadTreeListByProductionIds(String ids,String type);
    List<MdcEquipmentTree> loadTreeListByProductionIds(String ids);
    /**
     * æŸ¥è¯¢å•表数据
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -3,6 +3,7 @@
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;
@@ -18,7 +19,6 @@
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.DncDevicePermissionMapper;
import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper;
import org.jeecg.modules.mdc.mapper.MdcTorqueConfigMapper;
import org.jeecg.modules.mdc.model.MdcEquipmentTree;
@@ -28,6 +28,7 @@
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.DncDevicePermissionMapper;
import org.jeecg.modules.system.mapper.MdcEquipmentDepartMapper;
import org.jeecg.modules.system.mapper.MdcProductionEquipmentMapper;
import org.jeecg.modules.system.service.*;
@@ -220,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
@@ -232,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;
    }
@@ -273,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
@@ -347,7 +360,7 @@
    @Override
    public List<MdcEquipmentTree> loadTreeListByProduction(String userId,String type) {
    public List<MdcEquipmentTree> loadTreeListByProduction(String userId) {
        //获取所有产线数据
        List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
        //根据用户id获取拥有的产线信息集合
@@ -364,7 +377,7 @@
        //组装产线设备树
        List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
        //填充设备数据
        FillEquipmentByProduction(treeList,type);
        FillEquipmentByProduction(treeList);
        return treeList;
    }
@@ -663,9 +676,9 @@
    /**
     * äº§çº¿è®¾å¤‡æ ‘填充设备数据
     */
    private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList,String type) {
    private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList) {
        for (MdcEquipmentTree mdcEquipmentTree : treeList) {
            List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey(),type);
            List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey());
            if (equipmentList != null && !equipmentList.isEmpty()) {
                for (MdcEquipment mdcEquipment : equipmentList) {
                    MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
@@ -677,7 +690,7 @@
                mdcEquipmentTree.setLeaf(false);
            }
            if (!mdcEquipmentTree.getChildren().isEmpty()) {
                FillEquipmentByProduction(mdcEquipmentTree.getChildren(),type);
                FillEquipmentByProduction(mdcEquipmentTree.getChildren());
            }
        }
    }
@@ -885,7 +898,7 @@
     * @return
     */
    @Override
    public List<MdcEquipmentTree> loadTreeListByProductionIds(String ids,String type) {
    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));
@@ -901,7 +914,7 @@
        //组装产线设备树
        List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
        //填充设备数据
        FillEquipmentByProduction(treeList,type);
        FillEquipmentByProduction(treeList);
        return treeList;
    }
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/entity/DncDeviceGroupPermission.java
ÎļþÒÑɾ³ý
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/entity/DncDevicePermission.java
ÎļþÃû´Ó lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/DncDevicePermission.java ÐÞ¸Ä
@@ -1,4 +1,4 @@
package org.jeecg.modules.mdc.entity;
package org.jeecg.modules.system.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/DncDeviceGroupPermissionMapper.java
ÎļþÒÑɾ³ý
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/DncDevicePermissionMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,13 @@
package org.jeecg.modules.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.system.entity.DncDevicePermission;
/**
 * @author: Lyh
 * @description: è½¦é—´æƒé™Mapper接口
 * @create: 2023-04-07 11:17
 */
public interface DncDevicePermissionMapper extends BaseMapper<DncDevicePermission> {
}
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/MdcUserProductionMapper.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.system.entity.MdcUserProduction;
import org.jeecg.modules.system.entity.SysUser;
import java.util.List;
@@ -18,4 +19,33 @@
     * æ ¹æ®æŒ‡å®šç”¨æˆ·id查询产线id集合
     */
    List<String> queryProductionIdsByUserId(@Param("userId") String userId);
    /**
     * èŽ·å–å·²åˆ†é…çš„ç”¨æˆ·åˆ—è¡¨
     * @param proId
     * @return
     */
    List<SysUser> getUserPermsByGroupId(@Param("proId") String proId);
    /**
     * èŽ·å–æœªåˆ†é…çš„ç”¨æˆ·åˆ—è¡¨
     * @param proId
     * @return
     */
    List<SysUser> getUserNonPermsByGroupId(@Param("proId") String proId);
    /**
     * èŽ·å–è®¾å¤‡æœªåˆ†é…çš„ç”¨æˆ·
     * @param proId
     * @return
     */
    List<SysUser> getUserNonPermsByDeviceId(String proId);
    /**
     * èŽ·å–è®¾å¤‡å·²åˆ†é…çš„ç”¨æˆ·
     * @param deviceId
     * @return
     */
    List<SysUser> getUserPermsByDeviceId(String deviceId);
}
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/MdcUserProductionMapper.xml
@@ -6,4 +6,48 @@
    <select id="queryProductionIdsByUserId" resultType="java.lang.String">
        SELECT pro_id FROM mdc_user_production WHERE user_id = #{userId}
    </select>
</mapper>
    <select id="getUserPermsByGroupId" resultType="org.jeecg.modules.system.entity.SysUser">
        select u.id
             , u.username
             , u.realname
             , u.avatar
             , u.phone
             , u.email
        from sys_user u
                 inner join
             (select user_id from mdc_user_production where pro_id=#{proId}) p
             on u.id=p.user_id
    </select>
    <select id="getUserNonPermsByGroupId" resultType="org.jeecg.modules.system.entity.SysUser">
        select u.id
             , u.username
             , u.realname
             , u.avatar
             , u.phone
             , u.email
        from sys_user u
        where u.id not in (select user_id from mdc_user_production where pro_id=#{proId})
    </select>
    <select id="getUserNonPermsByDeviceId" resultType="org.jeecg.modules.system.entity.SysUser">
        select u.id
             , u.username
             , u.realname
             , u.avatar
             , u.phone
             , u.email
        from sys_user u
        where u.id not in (select user_id from nc_device_permission where device_id=#{deviceId})
    </select>
    <select id="getUserPermsByDeviceId" resultType="org.jeecg.modules.system.entity.SysUser">
        select u.id
             , u.username
             , u.realname
             , u.avatar
             , u.phone
             , u.email
        from sys_user u
                 inner join
                 (select user_id from nc_device_permission where device_id=#{deviceId}) p
                 on u.id=p.user_id
    </select>
</mapper>
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/IMdcUserProductionService.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.system.entity.MdcUserProduction;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.model.ProductionIdModel;
import java.util.List;
@@ -22,4 +23,42 @@
     * æ ¹æ®æŒ‡å®šç”¨æˆ·id查询产线id集合
     */
    List<String> queryProductionIdsByUserId(String userId);
    /**
     * åˆ é™¤ä¸€ç»„对象
     * @param mdcUserProductions
     * @return
     */
    boolean removeByCollection(List<MdcUserProduction> mdcUserProductions);
    /**
     * èŽ·å–å·²åˆ†é…çš„ç”¨æˆ·åˆ—è¡¨
     * @param proId
     * @return
     */
    List<SysUser> getUserPermsByGroupId(String proId);
    /**
     * èŽ·å–æœªåˆ†é…çš„ç”¨æˆ·åˆ—è¡¨
     * @param proId
     * @return
     */
    List<SysUser> getUserNonPermsByGroupId(String proId);
    /**
     * èŽ·å–æœªåˆ†é…çš„ç”¨æˆ·
     * @param proId
     * @return
     */
    List<SysUser> getUserNonPermsByDeviceId(String proId);
    /**
     * èŽ·å–å·²åˆ†é…çš„ç”¨æˆ·
     * @param proId
     * @return
     */
    List<SysUser> getUserPermsByDeviceId(String proId);
    MdcUserProduction getByUserIdAndGroupId(String userId, String proId);
}
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/MdcProductionServiceImpl.java
@@ -44,8 +44,6 @@
    @Resource
    private MdcProductionEquipmentMapper productionEquipmentMapper;
    @Resource
    private DncDeviceGroupPermissionMapper dncDeviceGroupPermissionMapper;
    /**
     * queryTreeList å¯¹åº” queryTreeList æŸ¥è¯¢æ‰€æœ‰çš„产线数据,以树结构形式响应给前端
     */
@@ -138,13 +136,6 @@
            mdcProduction.setOrgType(String.valueOf(orgType));
            mdcProduction.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
            this.save(mdcProduction);
            //新增DNC车间权限
            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
            String userId = user.getId();
            DncDeviceGroupPermission dncDeviceGroupPermission=new DncDeviceGroupPermission();
            dncDeviceGroupPermission.setGroupPermId(mdcProduction.getId());
            dncDeviceGroupPermission.setUserId(userId);
            dncDeviceGroupPermissionMapper.insert(dncDeviceGroupPermission);
        }
    }
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/MdcUserProductionServiceImpl.java
@@ -1,14 +1,17 @@
package org.jeecg.modules.system.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.entity.MdcUserProduction;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.MdcUserProductionMapper;
import org.jeecg.modules.system.model.ProductionIdModel;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.jeecg.modules.system.service.IMdcUserProductionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
@@ -63,4 +66,64 @@
    public List<String> queryProductionIdsByUserId(String userId) {
        return this.baseMapper.queryProductionIdsByUserId(userId);
    }
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean removeByCollection(List<MdcUserProduction> mdcUserProductions) {
        if(mdcUserProductions == null || mdcUserProductions.isEmpty())
            return false;
        if(mdcUserProductions.size() == 1){
            return super.removeById(mdcUserProductions.get(0).getId());
        }
        List<String> ids = new ArrayList<>();
        mdcUserProductions.forEach(item -> {
            ids.add(item.getId());
        });
        return super.removeByIds(ids);
    }
    /**
     * èŽ·å–å·²åˆ†é…çš„ç”¨æˆ·åˆ—è¡¨
     * @param proId
     * @return
     */
    @Override
    public List<SysUser> getUserPermsByGroupId(String proId){
        return super.getBaseMapper().getUserPermsByGroupId(proId);
    }
    /**
     * èŽ·å–æœªåˆ†é…çš„ç”¨æˆ·åˆ—è¡¨
     * @param proId
     * @return
     */
    @Override
    public List<SysUser> getUserNonPermsByGroupId(String proId){
        return super.getBaseMapper().getUserNonPermsByGroupId(proId);
    }
    /**
     * èŽ·å–æœªåˆ†é…çš„ç”¨æˆ·
     * @param proId
     * @return
     */
    @Override
    public List<SysUser> getUserNonPermsByDeviceId(String proId){
        return super.getBaseMapper().getUserNonPermsByDeviceId(proId);
    }
    @Override
    public List<SysUser> getUserPermsByDeviceId(String proId) {
        return super.getBaseMapper().getUserPermsByDeviceId(proId);
    }
    @Override
    public MdcUserProduction getByUserIdAndGroupId(String userId, String proId){
        if(StrUtil.isNotEmpty(userId) || !StrUtil.isNotEmpty(proId))
            return null;
        List<MdcUserProduction> list = super.lambdaQuery().eq(MdcUserProduction::getUserId, userId).eq(MdcUserProduction::getProId, proId).list();
        if(list == null || list.isEmpty())
            return null;
        return list.get(0);
    }
}
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
@@ -48,7 +48,7 @@
@Service
@Slf4j
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
    @Autowired
    private SysUserMapper userMapper;
    @Autowired
@@ -79,6 +79,10 @@
    MdcUserProductionMapper mdcUserProductionMapper;
    @Resource
    private ISysDictService sysDictService;
    @Resource
    private MdcProductionEquipmentMapper mdcProductionEquipmentMapper;
    @Resource
    private DncDevicePermissionMapper dncDevicePermissionMapper;
    @Override
    @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
@@ -141,8 +145,8 @@
    public SysUser getUserByName(String username) {
        return userMapper.getUserByName(username);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addUserWithRole(SysUser user, String roles) {
@@ -203,7 +207,7 @@
                roleIndex = list.get(0);
            }
        }
        //如果componentUrl为空,则返回空
        if(oConvertUtils.isEmpty(roleIndex.getComponent())){
            return null;
@@ -269,7 +273,7 @@
            info.setSysUserName(sysUser.getRealname());
            info.setSysOrgCode(sysUser.getOrgCode());
        }
        //多部门支持in查询
        List<SysDepart> list = sysDepartMapper.queryUserDeparts(sysUser.getId());
        List<String> sysMultiOrgCode = new ArrayList<String>();
@@ -285,7 +289,7 @@
            }
        }
        info.setSysMultiOrgCode(sysMultiOrgCode);
        return info;
    }
@@ -577,12 +581,24 @@
                sysUserDepartMapper.insert(userDeaprt);
            }
        }
        String[] arr = {};
        //step.4 ä¿å­˜æ‰€å±žäº§çº¿
        if (oConvertUtils.isNotEmpty(selectedProductions)) {
            String[] arr = selectedProductions.split(",");
            arr = selectedProductions.split(",");
            for (String productionId : arr) {
                MdcUserProduction mdcUserProduction = new MdcUserProduction(user.getId(), productionId);
                mdcUserProductionMapper.insert(mdcUserProduction);
            }
        }
        //step.5 ä¿å­˜è®¾å¤‡æƒé™
        List<String> EquipmentIds= mdcProductionEquipmentMapper.selectList(new QueryWrapper<MdcProductionEquipment>().in("production_id",arr))
                .stream().map(MdcProductionEquipment::getEquipmentId).collect(Collectors.toList());
        if (oConvertUtils.isNotEmpty(EquipmentIds)) {
            for (String equipmentId : EquipmentIds) {
                DncDevicePermission dncDevicePermission=new DncDevicePermission();
                dncDevicePermission.setDeviceId(equipmentId);
                dncDevicePermission.setUserId(user.getId());
                dncDevicePermissionMapper.insert(dncDevicePermission);
            }
        }
    }
@@ -646,7 +662,20 @@
                mdcUserProductionMapper.insert(mdcUserProduction);
            }
        }
        //step.5 ä¿®æ”¹æ‰‹æœºå·å’Œé‚®ç®±
        //step.5 ä¿®æ”¹è®¾å¤‡æƒé™
        //先删后加
        dncDevicePermissionMapper.delete(new QueryWrapper<DncDevicePermission>().lambda().eq(DncDevicePermission::getUserId, user.getId()));
        List<String> EquipmentIds= mdcProductionEquipmentMapper.selectList(new QueryWrapper<MdcProductionEquipment>().in("production_id",array))
                .stream().map(MdcProductionEquipment::getEquipmentId).collect(Collectors.toList());
        if (oConvertUtils.isNotEmpty(EquipmentIds)) {
            for (String equipmentId : EquipmentIds) {
                DncDevicePermission dncDevicePermission=new DncDevicePermission();
                dncDevicePermission.setDeviceId(equipmentId);
                dncDevicePermission.setUserId(user.getId());
                dncDevicePermissionMapper.insert(dncDevicePermission);
            }
        }
        //step.6 ä¿®æ”¹æ‰‹æœºå·å’Œé‚®ç®±
        // æ›´æ–°æ‰‹æœºå·ã€é‚®ç®±ç©ºå­—符串为 null
        userMapper.updateNullByEmptyString("email");
        userMapper.updateNullByEmptyString("phone");