From 2fb6c67b2c0c72195eef6fe5f7904d739b46e2c0 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期三, 25 六月 2025 11:57:28 +0800
Subject: [PATCH] Merge branch 'mdc_hyjs_master'

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PartsInfoServiceImpl.java |  127 ++++++++++++++++++++++++++++++++++-------
 1 files changed, 104 insertions(+), 23 deletions(-)

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PartsInfoServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PartsInfoServiceImpl.java
index 379abd8..59e70c2 100644
--- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PartsInfoServiceImpl.java
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/PartsInfoServiceImpl.java
@@ -1,5 +1,7 @@
 package org.jeecg.modules.dnc.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
+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.toolkit.Wrappers;
@@ -7,11 +9,14 @@
 import org.apache.commons.collections4.ListUtils;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum;
 import org.jeecg.modules.dnc.entity.*;
 import org.jeecg.modules.dnc.exception.ExceptionCast;
 import org.jeecg.modules.dnc.mapper.ComponentInfoMapper;
 import org.jeecg.modules.dnc.mapper.PartsInfoMapper;
 import org.jeecg.modules.dnc.mapper.ProductInfoMapper;
+import org.jeecg.modules.dnc.request.DocInfoQueryRequest;
+import org.jeecg.modules.dnc.request.TreeInfoRequest;
 import org.jeecg.modules.dnc.response.CommonCode;
 import org.jeecg.modules.dnc.response.PartsInfoCode;
 import org.jeecg.modules.dnc.response.ProductInfoCode;
@@ -21,13 +26,12 @@
 import org.jeecg.modules.system.entity.MdcProduction;
 import org.jeecg.modules.system.entity.SysUser;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class PartsInfoServiceImpl extends ServiceImpl<PartsInfoMapper, PartsInfo> implements IPartsInfoService {
@@ -44,11 +48,18 @@
     @Autowired
     private IProcessSpecVersionService processSpecVersionService;
     @Autowired
+    private IProcessStreamService processStreamService;
+    @Autowired
+    private IWorkStepService workStepService;
+    @Autowired
     private IDocRelativeService iDocRelativeService;
     @Autowired
     private IProductPermissionService productPermissionService;
     @Autowired
     private IProductMixService productMixService;
+    @Autowired
+    @Lazy
+    private IDocInfoService docInfoService;
     @Override
     @Transactional(rollbackFor = {Exception.class})
     public boolean addPartsInfo(PartsInfo partsInfo) {
@@ -77,7 +88,7 @@
             ExceptionCast.cast(PartsInfoCode.PARTS_COMPONENT_NONE);
         partsInfo.setPartsStatus(1);
         boolean b = super.save(partsInfo);
-        List<PermissionStreamNew> oldDepartPermList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(componentInfo.getComponentId(),"2","1");
+        List<PermissionStreamNew> oldDepartPermList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(componentInfo.getComponentId(),DocAttributionTypeEnum.COMPONENT.getCode().toString(),"1");
         if(oldDepartPermList != null && !oldDepartPermList.isEmpty()) {
             List<PartsDepartment> partsDepartmentList = new ArrayList<>();
             List<PermissionStreamNew> permissionStreamList = new ArrayList<>();
@@ -89,7 +100,7 @@
                 PermissionStreamNew perm = new PermissionStreamNew();
                 perm.setDepartId(item.getDepartId());
                 perm.setBusinessId(partsInfo.getPartsId());
-                perm.setBusinessType("3");
+                perm.setBusinessType(DocAttributionTypeEnum.PARTS.getCode().toString());
                 permissionStreamList.add(perm);
             });
             if(!partsDepartmentList.isEmpty()) {
@@ -105,20 +116,20 @@
         }
         if(!b)
             ExceptionCast.cast(CommonCode.FAIL);
-        b = productPermissionService.add(partsInfo.getPartsId(), userId,"3");
+        b = productPermissionService.add(partsInfo.getPartsId(), userId,DocAttributionTypeEnum.PARTS.getCode().toString());
         if (!b) {
             ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR);
         }
         //娣诲姞缁撴瀯鏍�
         ProductMix productMix = new ProductMix(Long.parseLong(partsInfo.getPartsId()),Long.parseLong(partsInfo.getComponentId())
-                ,partsInfo.getPartsName(),partsInfo.getPartsCode(),"3");
+                ,partsInfo.getPartsName(),partsInfo.getPartsCode(),DocAttributionTypeEnum.PARTS.getCode(),new Date());
         productMixService.save(productMix);
         //娣诲姞鐢ㄦ埛鏉冮檺
         PermissionStreamNew stream = new PermissionStreamNew();
         stream.setBusinessId(partsInfo.getPartsId());
-        stream.setBusinessType("3");
+        stream.setBusinessType(DocAttributionTypeEnum.PARTS.getCode().toString());
         stream.setUserId(userId);
-        return permissionStreamNewService.save(stream);
+        return permissionStreamNewService.addPermissionStreamNew(stream);
     }
 
     @Override
@@ -138,6 +149,11 @@
         partsInfo.setProductId(null);
         partsInfo.setComponentId(null);
         boolean b = super.updateById(partsInfo);
+        //鍚屾淇敼缁撴瀯鏍�
+        ProductMix productMix = productMixService.getById(Long.parseLong(id));
+        productMix.setTreeName(partsInfo.getPartsName());
+        productMix.setTreeCode(partsInfo.getPartsCode());
+        productMixService.updateById(productMix);
         if(!b)
             return false;
         PartsPermission permission = partsPermissionService.getByPartsIdAndUserId(id, userId);
@@ -149,11 +165,11 @@
             if(!b)
                 return false;
         }
-        PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId( id, userId,"3");
+        PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId( id, userId,DocAttributionTypeEnum.PARTS.getCode().toString());
         if(stream == null) {
             stream = new PermissionStreamNew();
             stream.setBusinessId(id);
-            stream.setBusinessType("3");
+            stream.setBusinessType(DocAttributionTypeEnum.PARTS.getCode().toString());
             stream.setUserId(userId);
             return permissionStreamNewService.save(stream);
         }
@@ -211,10 +227,10 @@
             b = partsDepartmentService.deleteByPartsId(item.getPartsId());
             if(!b)
                 ExceptionCast.cast(PartsInfoCode.PARTS_DELETE_ERROR);
-            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getPartsId(),"3","0");
+            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getPartsId(),DocAttributionTypeEnum.PARTS.getCode().toString(),"0");
             if(!b)
                 ExceptionCast.cast(PartsInfoCode.PARTS_DELETE_ERROR);
-            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getPartsId(),"3","1");
+            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getPartsId(),DocAttributionTypeEnum.PARTS.getCode().toString(),"1");
             if(!b)
                 ExceptionCast.cast(PartsInfoCode.PARTS_DELETE_ERROR);
             b = super.removeById(item.getPartsId());
@@ -237,7 +253,7 @@
             ExceptionCast.cast(PartsInfoCode.PARTS_PROCESS_EXIST);
         boolean b = partsPermissionService.deleteByPartsId(partsInfo.getPartsId());
         //楠岃瘉鏄惁瀛樺湪鏂囨。
-        List<DocRelative> docRelativeList=iDocRelativeService.list(new QueryWrapper<DocRelative>().eq("attribution_type","3").eq("attribution_id",partsId));
+        List<DocRelative> docRelativeList=iDocRelativeService.list(new QueryWrapper<DocRelative>().eq("attribution_type",DocAttributionTypeEnum.PARTS.getCode().toString()).eq("attribution_id",partsId));
         if (!docRelativeList.isEmpty()){
             ExceptionCast.cast(PartsInfoCode.PARTS_DOC_EXIST);
         }
@@ -246,10 +262,10 @@
         b = partsDepartmentService.deleteByPartsId(partsInfo.getPartsId());
         if(!b)
             ExceptionCast.cast(CommonCode.FAIL);
-        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(partsId,"3","0");
+        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(partsId,DocAttributionTypeEnum.PARTS.getCode().toString(),"0");
         if(!b)
             ExceptionCast.cast(CommonCode.FAIL);
-        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(partsId,"3","1");
+        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(partsId,DocAttributionTypeEnum.PARTS.getCode().toString(),"1");
         if(!b)
             ExceptionCast.cast(CommonCode.FAIL);
         b = productMixService.removeById(partsId);
@@ -273,12 +289,12 @@
                 en.setPartsId(partsInfo.getPartsId());
                 permissionList.add(en);
             }
-            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(partsInfo.getPartsId(), item.getId(),"3");
+            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(partsInfo.getPartsId(), item.getId(),DocAttributionTypeEnum.PARTS.getCode().toString());
             if(stream == null) {
                 stream = new PermissionStreamNew();
                 stream.setUserId(item.getId());
                 stream.setBusinessId(partsInfo.getPartsId());
-                stream.setBusinessType("3");
+                stream.setBusinessType(DocAttributionTypeEnum.PARTS.getCode().toString());
                 permissionStreamList.add(stream);
             }
         });
@@ -309,7 +325,7 @@
             if(en != null) {
                 permissionList.add(en);
             }
-            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(partsInfo.getPartsId(), item.getId(),"3");
+            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(partsInfo.getPartsId(), item.getId(),DocAttributionTypeEnum.PARTS.getCode().toString());
             if(stream != null) {
                 permissionStreamList.add(stream);
             }
@@ -345,12 +361,12 @@
                 en.setPartsId(partsInfo.getPartsId());
                 partsDepartments.add(en);
             }
-            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(partsInfo.getPartsId(), item.getId(),"3");
+            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(partsInfo.getPartsId(), item.getId(),DocAttributionTypeEnum.PARTS.getCode().toString());
             if(stream == null) {
                 stream = new PermissionStreamNew();
                 stream.setDepartId(item.getId());
                 stream.setBusinessId(partsInfo.getPartsId());
-                stream.setBusinessType("3");
+                stream.setBusinessType(DocAttributionTypeEnum.PARTS.getCode().toString());
                 permissionStreamList.add(stream);
             }
         });
@@ -381,7 +397,7 @@
             if(en != null) {
                 partsDepartments.add(en);
             }
-            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(partsInfo.getPartsId(), item.getId(),"3");
+            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(partsInfo.getPartsId(), item.getId(),DocAttributionTypeEnum.PARTS.getCode().toString());
             if(stream != null) {
                 permissionStreamList.add(stream);
             }
@@ -433,4 +449,69 @@
         return null;
     }
 
+    /**
+     * 閫氳繃闆朵欢鍙枫�佹潗璐ㄧ瓑鏌ヨ瀵瑰簲鐢靛瓙鏍锋澘
+     * @param treeInfoRequest
+     * @return
+     */
+    @Override
+    public List<DocInfo> getByPartsInfo(TreeInfoRequest treeInfoRequest){
+        LambdaQueryWrapper<PartsInfo> queryWrapper = new LambdaQueryWrapper<>();
+        if (treeInfoRequest.getProductIds() != null && !treeInfoRequest.getProductIds().isEmpty()) {
+            queryWrapper.in(PartsInfo::getProductId, treeInfoRequest.getProductIds());
+        }
+        if (treeInfoRequest.getComponentIds() != null && !treeInfoRequest.getComponentIds().isEmpty()) {
+            queryWrapper.in(PartsInfo::getComponentId, treeInfoRequest.getComponentIds());
+        }
+        if (Objects.equals(treeInfoRequest.getAttributionType(), DocAttributionTypeEnum.PARTS.getCode())){
+            queryWrapper.eq(StrUtil.isNotEmpty(treeInfoRequest.getAttributionId()),PartsInfo::getPartsId,treeInfoRequest.getAttributionId());
+        }
+        queryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeCode()),PartsInfo::getPartsCode, treeInfoRequest.getTreeCode());
+        queryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeName()),PartsInfo::getPartsName, treeInfoRequest.getTreeName());
+        queryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getStructureType()),PartsInfo::getStructureType, treeInfoRequest.getStructureType());
+        queryWrapper.orderByDesc(PartsInfo::getCreateTime);
+        List<PartsInfo> list = super.list(queryWrapper);
+        List<DocInfo> docInfos = new ArrayList<>();
+        if (list != null && !list.isEmpty()) {
+            String ids=list.stream().map(PartsInfo::getPartsId).collect(Collectors.joining(","));
+            DocInfoQueryRequest docQuery = new DocInfoQueryRequest();
+            BeanUtil.copyProperties(treeInfoRequest,docQuery);
+            docQuery.setAttributionIds(ids);
+            docQuery.setDocClassCode("OTHER");
+            docQuery.setAttributionType(DocAttributionTypeEnum.PARTS.getCode());
+            docInfos=docInfoService.findListByDocQuery(docQuery);
+        }
+        if (Objects.equals(treeInfoRequest.getAttributionType(), DocAttributionTypeEnum.PARTS.getCode())){
+            List<String> id =new ArrayList<>();
+            id.add(treeInfoRequest.getAttributionId());
+            treeInfoRequest.setPartsIds(id);
+            //宸ヨ壓瑙勭▼鐗堟湰
+            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;
+    }
+
+    @Override
+    public boolean assignPermission(Object entity, Collection<SysUser> userList, boolean isAdd){
+        if (isAdd) {
+            return assignAddUser((PartsInfo) entity, userList);
+        } else {
+            return assignRemoveUser((PartsInfo) entity, userList);
+        }
+    }
+    @Override
+    public boolean assignDepartPermission(Object entity, Collection<MdcProduction> departments, boolean isAdd) {
+        if (isAdd) {
+            return assignAddDepart((PartsInfo) entity, departments);
+        } else {
+            return assignRemoveDepart((PartsInfo) entity, departments);
+        }
+    }
 }

--
Gitblit v1.9.3