From cc44920da3d40b8248b67560026e891afdd1a6ab Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期四, 08 五月 2025 17:57:14 +0800
Subject: [PATCH] 1.查询可以被引用的部件接口开发完成 2.借用部件(可批量) 开发完成 3.修改原有新增、修改部件接口 完成 4.修改原有删除文档与导入文档接口 完成 5.修改工作流问题

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ComponentInfoSeServiceImpl.java |  122 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 119 insertions(+), 3 deletions(-)

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ComponentInfoSeServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ComponentInfoSeServiceImpl.java
index 9b22567..986a593 100644
--- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ComponentInfoSeServiceImpl.java
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ComponentInfoSeServiceImpl.java
@@ -4,9 +4,12 @@
 import cn.hutool.core.util.StrUtil;
 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.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.dnc.dto.ComponentExt;
 import org.jeecg.modules.dnc.entity.*;
@@ -57,6 +60,8 @@
     @Autowired
     @Lazy
     private IDocInfoService docInfoService;
+    @Autowired
+    private IDocRelativeService docRelativeService;
     @Override
     @Transactional(rollbackFor = {Exception.class})
     public boolean addComponentInfo(ComponentInfo componentInfo) {
@@ -69,7 +74,7 @@
         if(!ValidateUtil.validateString(componentInfo.getComponentCode()))
             ExceptionCast.cast(ComponentInfoCode.COMPONENT_CODE_NONE);
         ComponentInfo en = getByCode(componentInfo.getComponentCode());
-        if(en != null)
+        if(en != null&&componentInfo.getBorrowId()==null)
             ExceptionCast.cast(ComponentInfoCode.COMPONENT_IS_EXIST);
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         String userId = user.getId();
@@ -137,6 +142,20 @@
                     ,componentInfo.getComponentName(),componentInfo.getComponentCode(),2,new Date());
         }
         productMixService.save(productMix);
+        if (StrUtil.isNotEmpty(componentInfo.getBorrowId())){
+            //鍊熺敤閮ㄤ欢,鍚屾娣诲姞鏂囦欢
+            List<DocRelative> docRelativeList=docRelativeService.
+                    list(new QueryWrapper<DocRelative>().eq("attribution_type","2").eq("attribution_id",componentInfo.getBorrowId()));
+            if (!docRelativeList.isEmpty()){
+                docRelativeList.forEach(item -> {
+                    DocRelative docRelative = new DocRelative();
+                    BeanUtil.copyProperties(item,docRelative);
+                    docRelative.setId(null);
+                    docRelative.setAttributionId(componentInfo.getComponentId());
+                    docRelativeService.save(docRelative);
+                });
+            }
+        }
         //娣诲姞鏉冮檺
         PermissionStreamNew stream = new PermissionStreamNew();
         stream.setUserId(userId);
@@ -189,7 +208,11 @@
             stream.setBusinessType("2");
             return permissionStreamNewService.save(stream);
         }
-        return b;
+        List<ComponentInfo> list = super.lambdaQuery().eq(ComponentInfo::getBorrowId,id).list();
+        if (list != null && !list.isEmpty()) {
+            list.forEach(item -> editComponentInfo(item.getComponentId(),componentInfo));
+        }
+        return true;
     }
 
     @Override
@@ -267,14 +290,20 @@
         if(childrenList != null && !childrenList.isEmpty()) {
             ExceptionCast.cast(ComponentInfoCode.COMPONENT_CHILD_EXIST);
         }
-        //楠岃瘉浜у搧涓嬫槸鍚︽湁闆朵欢
+        //楠岃瘉閮ㄤ欢涓嬫槸鍚︽湁闆朵欢
         List<PartsInfo> partsInfoList = partsInfoService.getByComponentId(componentInfo.getProductId(), componentInfo.getComponentId());
         if(partsInfoList != null && !partsInfoList.isEmpty()) {
             ExceptionCast.cast(ComponentInfoCode.COMPONENT_PARTS_EXIST);
         }
+        //楠岃瘉閮ㄤ欢涓嬫槸鍚︽湁宸ュ簭淇℃伅
         List<ProcessStream> processStreamList = processStreamService.findByComponentId(id);
         if(processStreamList != null && !processStreamList.isEmpty()) {
             ExceptionCast.cast(ComponentInfoCode.COMPONENT_PROCESS_EXIST);
+        }
+        //楠岃瘉閮ㄤ欢鏄惁琚�熺敤
+        List<ComponentInfo> list = super.lambdaQuery().eq(ComponentInfo::getBorrowId,id).list();
+        if (list != null && !list.isEmpty()) {
+            ExceptionCast.cast(ComponentInfoCode.COMPONENT_BORROW_EXIST);
         }
         boolean b;
         //楠岃瘉鏄惁瀛樺湪鏂囨。
@@ -566,4 +595,91 @@
         }
         return docInfos;
     }
+
+    /**
+     * 鏌ヨ鍙互琚紩鐢ㄧ殑閮ㄤ欢
+     * @param componentInfo
+     * @param pageNo
+     * @param pageSize
+     * @return
+     */
+    @Override
+    public IPage<ComponentInfo> getByComponentId(ComponentInfo componentInfo, Integer pageNo, Integer pageSize){
+        //鏉冮檺鎺掗櫎,涓嶈兘寮曠敤鑷繁涓婁笅绾ч儴浠�
+        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        String productIds = loginUser.getProductionIds();
+        IPage<ComponentInfo> page = new Page<>(pageNo, pageSize);
+        if (productIds != null && !productIds.isEmpty()) {
+            List<String> productIdList = Arrays.asList(productIds.split(","));
+            List<ProductMix> productMixList = permissionStreamNewService.
+                    loadProductMixByBusinessIdAndBusinessType(loginUser.getId(),productIdList,componentInfo.getComponentId(),"2");
+            List<Long> ids = productMixList.stream().map(ProductMix::getId).collect(Collectors.toList());
+            //鑾峰彇宸茬粡琚�熺敤鐨勯儴浠�
+            LambdaQueryWrapper<ComponentInfo> borrowQueryWrapper = new LambdaQueryWrapper<>();
+            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 (!borrowIds.isEmpty()) {
+                queryWrapper.notIn(ComponentInfo::getComponentId,borrowIds);
+            }
+            queryWrapper.orderByDesc(ComponentInfo::getCreateTime);
+            page = super.page(page, queryWrapper);
+        }
+        return page;
+    }
+
+    /**
+     * 鍊熺敤閮ㄤ欢(鍙壒閲�) - 鍘熸湁閮ㄤ欢id锛屾柊閮ㄤ欢ids
+     * @param oldId,newIds
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> borrowComponent(String oldId, String newIds){
+        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        ComponentInfo componentInfo = super.getById(oldId);
+        if(componentInfo == null) {
+            return Result.error("閮ㄤ欢涓嶅瓨鍦�");
+        }
+        List<String> productIdList = Arrays.asList(loginUser.getProductionIds().split(","));
+        //鑾峰彇鍙互鍊熺敤鐨勯儴浠�
+        List<ProductMix> productMixList = permissionStreamNewService.
+                loadProductMixByBusinessIdAndBusinessType(loginUser.getId(),productIdList,componentInfo.getComponentId(),"2");
+        Set<Long> allowedIds = productMixList.stream()
+                .map(ProductMix::getId)
+                .collect(Collectors.toCollection(HashSet::new));
+        List<String> newIdList = Arrays.asList(newIds.split(","));
+        boolean allAllowed = newIdList.parallelStream()
+                .map(Long::parseLong)
+                .allMatch(allowedIds::contains);
+        if (!allAllowed) {
+            return Result.error("瀛樺湪鏈巿鏉冪殑閮ㄤ欢鍊熺敤");
+        }
+        //鑾峰彇宸茬粡琚�熺敤鐨勯儴浠�
+        LambdaQueryWrapper<ComponentInfo> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.in(ComponentInfo::getBorrowId,newIdList);
+        queryWrapper.eq(ComponentInfo::getParentId,componentInfo.getComponentId());
+        List<ComponentInfo> list = super.list(queryWrapper);
+        //鍒ゆ柇鏄惁宸茬粡琚綋鍓嶉儴浠跺�熺敤
+        if(!list.isEmpty()) {
+            return Result.error("閫夋嫨鐨勯儴浠跺凡琚綋鍓嶉儴浠跺�熺敤");
+        }
+        List<ComponentInfo> componentInfoList=listByIds(newIdList);
+        componentInfoList.forEach(item->{
+            //娣诲姞閮ㄤ欢淇℃伅銆佸眰绾т俊鎭�佹潈闄愪俊鎭�
+            ComponentInfo newComponentInfo=new ComponentInfo();
+            BeanUtil.copyProperties(item,newComponentInfo);
+            newComponentInfo.setComponentId(null);
+            newComponentInfo.setProductId(componentInfo.getProductId());
+            newComponentInfo.setParentId(componentInfo.getComponentId());
+            newComponentInfo.setBorrowId(item.getComponentId());
+            addComponentInfo(newComponentInfo);
+        });
+        return Result.ok("閮ㄤ欢鍊熺敤鎴愬姛");
+    }
 }

--
Gitblit v1.9.3