lyh
2025-02-17 1dcf43467f34eb70002be3c2f3cd7605ceb5dcdd
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);
            }