hyingbo
7 天以前 cc0e9036de6e922e8fe254fef01d8de9996024b7
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ComponentInfoSeServiceImpl.java
@@ -11,6 +11,7 @@
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum;
import org.jeecg.modules.dnc.dto.ComponentExt;
import org.jeecg.modules.dnc.entity.*;
import org.jeecg.modules.dnc.exception.ExceptionCast;
@@ -52,6 +53,8 @@
    @Autowired
    private IProcessStreamService processStreamService;
    @Autowired
    private IWorkStepService workStepService;
    @Autowired
    private IProductMixService productMixService;
    @Autowired
    private IDocRelativeService iDocRelativeService;
@@ -89,10 +92,10 @@
            if(en == null) {
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_PARENT_NOT_EXIST);
            }
            oldPermissionList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(en.getComponentId(),"2","1");
            oldPermissionList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(en.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"1");
            componentInfo.setRankLevel(en.getRankLevel() + 1);
        } else {
            oldPermissionList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(productInfo.getProductId(),"1","1");
            oldPermissionList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(productInfo.getProductId(),DocAttributionTypeEnum.PRODUCT.getCode().toString(),"1");
            componentInfo.setParentId(null);
            componentInfo.setRankLevel(1);
        }
@@ -113,7 +116,7 @@
                PermissionStreamNew permissionStream = new PermissionStreamNew();
                permissionStream.setBusinessId(componentInfo.getComponentId());
                permissionStream.setDepartId(item.getDepartId());
                permissionStream.setBusinessType("2");
                permissionStream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString());
                componentDepartPermList.add(permissionStream);
            });
        }
@@ -127,7 +130,7 @@
            if(!b)
                ExceptionCast.cast(CommonCode.FAIL);
        }
        b = productPermissionService.add(componentInfo.getComponentId(), userId,"2");
        b = productPermissionService.add(componentInfo.getComponentId(), userId,DocAttributionTypeEnum.COMPONENT.getCode().toString());
        if (!b) {
            ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR);
        }
@@ -145,7 +148,7 @@
        if (StrUtil.isNotEmpty(componentInfo.getBorrowId())){
            //借用部件,同步添加文件
            List<DocRelative> docRelativeList=docRelativeService.
                    list(new QueryWrapper<DocRelative>().eq("attribution_type","2").eq("attribution_id",componentInfo.getBorrowId()));
                    list(new QueryWrapper<DocRelative>().eq("attribution_type",DocAttributionTypeEnum.COMPONENT.getCode().toString()).eq("attribution_id",componentInfo.getBorrowId()));
            if (!docRelativeList.isEmpty()){
                docRelativeList.forEach(item -> {
                    DocRelative docRelative = new DocRelative();
@@ -160,7 +163,7 @@
        PermissionStreamNew stream = new PermissionStreamNew();
        stream.setUserId(userId);
        stream.setBusinessId(componentInfo.getComponentId());
        stream.setBusinessType("2");
        stream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString());
        return permissionStreamNewService.addPermissionStreamNew(stream);
    }
@@ -186,8 +189,8 @@
        boolean b = super.updateById(componentInfo);
        //同步修改结构树
        ProductMix productMix = productMixService.getById(Long.parseLong(id));
        productMix.setName(componentInfo.getComponentName());
        productMix.setCode(componentInfo.getComponentCode());
        productMix.setTreeName(componentInfo.getComponentName());
        productMix.setTreeCode(componentInfo.getComponentCode());
        productMixService.updateById(productMix);
        if(!b)
            return false;
@@ -200,12 +203,12 @@
            if(!b)
                return false;
        }
        PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(id, userId,"2");
        PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(id, userId,DocAttributionTypeEnum.COMPONENT.getCode().toString());
        if(stream == null) {
            stream = new PermissionStreamNew();
            stream.setUserId(userId);
            stream.setBusinessId(id);
            stream.setBusinessType("2");
            stream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString());
            return permissionStreamNewService.save(stream);
        }
        List<ComponentInfo> list = super.lambdaQuery().eq(ComponentInfo::getBorrowId,id).list();
@@ -265,10 +268,10 @@
            b = componentDepartmentService.deleteByComponentId(item.getComponentId());
            if(!b)
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_DELETE_PERM_NONE);
            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getComponentId(),"2","0");
            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"0");
            if(!b)
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_DELETE_PERM_NONE);
            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getComponentId(),"2","1");
            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"1");
            if(!b)
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_DELETE_PERM_NONE);
            b = super.removeById(item.getComponentId());
@@ -307,7 +310,7 @@
        }
        boolean b;
        //验证是否存在文档
        List<DocRelative> docRelativeList=iDocRelativeService.list(new QueryWrapper<DocRelative>().eq("attribution_type","2").eq("attribution_id",id));
        List<DocRelative> docRelativeList=iDocRelativeService.list(new QueryWrapper<DocRelative>().eq("attribution_type",DocAttributionTypeEnum.COMPONENT.getCode().toString()).eq("attribution_id",id));
        if (!docRelativeList.isEmpty()){
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_DOC_EXIST);
        }
@@ -317,10 +320,10 @@
        b = componentDepartmentService.deleteByComponentId(id);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(componentInfo.getComponentId(),"2","0");
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(componentInfo.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"0");
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(componentInfo.getComponentId(),"2","1");
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(componentInfo.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"1");
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = productMixService.removeById(id);
@@ -361,7 +364,7 @@
                stream = new PermissionStreamNew();
                stream.setUserId(item.getId());
                stream.setBusinessId(componentInfo.getComponentId());
                stream.setBusinessType("2");
                stream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString());
                permissionStreamList.add(stream);
            }
        });
@@ -431,12 +434,12 @@
                en.setComponentId(componentInfo.getComponentId());
                componentDepartments.add(en);
            }
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(),"2");
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(),DocAttributionTypeEnum.COMPONENT.getCode().toString());
            if(stream == null) {
                stream = new PermissionStreamNew();
                stream.setDepartId(item.getId());
                stream.setBusinessId(componentInfo.getComponentId());
                stream.setBusinessType("2");
                stream.setBusinessType(DocAttributionTypeEnum.COMPONENT.getCode().toString());
                permissionStreamList.add(stream);
            }
        });
@@ -467,7 +470,7 @@
            if(en != null) {
                componentDepartments.add(en);
            }
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(),"2");
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(),DocAttributionTypeEnum.COMPONENT.getCode().toString());
            if(stream != null) {
                permissionStreamList.add(stream);
            }
@@ -588,10 +591,18 @@
            List<String> id =new ArrayList<>();
            id.add(treeInfoRequest.getAttributionId());
            treeInfoRequest.setComponentIds(id);
            //零件
            List<DocInfo> partsInfos = partsInfoService.getByPartsInfo(treeInfoRequest);
            docInfos.addAll(partsInfos);
            //工艺规程版本
            List<DocInfo> processSpecVersions = processSpecVersionService.getByProcessSpecVersion(treeInfoRequest);
            docInfos.addAll(processSpecVersions);
            //工序
            List<DocInfo> processStreams = processStreamService.getByProcessStreamOtherFile(treeInfoRequest);
            docInfos.addAll(processStreams);
            //工步
            List<DocInfo> workSteps = workStepService.getByWorkStepOtherFile(treeInfoRequest);
            docInfos.addAll(workSteps);
        }
        return docInfos;
    }
@@ -613,18 +624,22 @@
        if (productIds != null && !productIds.isEmpty()) {
            List<String> productIdList = Arrays.asList(productIds.split(","));
            List<ProductMix> productMixList = permissionStreamNewService.
                    loadProductMixByBusinessIdAndBusinessType(loginUser.getId(),productIdList,componentInfo.getComponentId(),"2");
                    loadProductMixByBusinessIdAndBusinessType(loginUser.getId(),productIdList,componentInfo.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString());
            List<Long> ids = productMixList.stream().map(ProductMix::getId).collect(Collectors.toList());
            //获取已经自身被借用的部件
            LambdaQueryWrapper<ComponentInfo> borrowQueryWrapper = new LambdaQueryWrapper<>();
            borrowQueryWrapper.in(ComponentInfo::getBorrowId,ids);
            if (!ids.isEmpty()){
                borrowQueryWrapper.in(ComponentInfo::getBorrowId,ids);
            }
            borrowQueryWrapper.eq(ComponentInfo::getParentId,componentInfo.getComponentId());
            List<String> borrowIds= super.list(borrowQueryWrapper).stream().map(ComponentInfo::getBorrowId).collect(Collectors.toList());
            LambdaQueryWrapper<ComponentInfo> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.like(StrUtil.isNotEmpty(componentInfo.getComponentName()),ComponentInfo::getComponentName, componentInfo.getComponentName());
            queryWrapper.like(StrUtil.isNotEmpty(componentInfo.getComponentCode()),ComponentInfo::getComponentCode, componentInfo.getComponentCode());
            queryWrapper.isNull(ComponentInfo::getBorrowId);
            queryWrapper.in(ComponentInfo::getComponentId,ids);
            if (!ids.isEmpty()){
                queryWrapper.in(ComponentInfo::getComponentId,ids);
            }
            queryWrapper.ne(StrUtil.isNotEmpty(oldComponentInfo.getBorrowId()),ComponentInfo::getComponentId,oldComponentInfo.getBorrowId());
            if (!borrowIds.isEmpty()) {
                queryWrapper.notIn(ComponentInfo::getComponentId,borrowIds);
@@ -651,7 +666,7 @@
        List<String> productIdList = Arrays.asList(loginUser.getProductionIds().split(","));
        //获取可以借用的部件
        List<ProductMix> productMixList = permissionStreamNewService.
                loadProductMixByBusinessIdAndBusinessType(loginUser.getId(),productIdList,componentInfo.getComponentId(),"2");
                loadProductMixByBusinessIdAndBusinessType(loginUser.getId(),productIdList,componentInfo.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString());
        Set<Long> allowedIds = productMixList.stream()
                .map(ProductMix::getId)
                .collect(Collectors.toCollection(HashSet::new));
@@ -688,4 +703,21 @@
        });
        return Result.ok("部件借用成功");
    }
    @Override
    public boolean assignPermission(Object entity, Collection<SysUser> userList, boolean isAdd){
        if (isAdd) {
            return assignAddUser((ComponentInfo) entity, userList);
        } else {
            return assignRemoveUser((ComponentInfo) entity, userList);
        }
    }
    @Override
    public boolean assignDepartPermission(Object entity, Collection<MdcProduction> departments, boolean isAdd) {
        if (isAdd) {
            return assignAddDepart((ComponentInfo) entity, departments);
        } else {
            return assignRemoveDepart((ComponentInfo) entity, departments);
        }
    }
}