From 00bbe79dde88659a4ac7a8f9621ea3a9c730bb91 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期六, 08 二月 2025 13:57:29 +0800
Subject: [PATCH] 修改权限配置

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessStreamServiceImpl.java |  149 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 141 insertions(+), 8 deletions(-)

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessStreamServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessStreamServiceImpl.java
index 813f313..6462d98 100644
--- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessStreamServiceImpl.java
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessStreamServiceImpl.java
@@ -1,29 +1,33 @@
 package org.jeecg.modules.dnc.service.impl;
 
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.dnc.exception.ExceptionCast;
 import org.jeecg.modules.dnc.mapper.ProcessStreamMapper;
-import org.jeecg.modules.dnc.response.CommonCode;
-import org.jeecg.modules.dnc.response.ComponentInfoCode;
-import org.jeecg.modules.dnc.response.DeviceCode;
-import org.jeecg.modules.dnc.response.ProcessInfoCode;
+import org.jeecg.modules.dnc.response.*;
 
 import org.jeecg.modules.dnc.service.*;
+import org.jeecg.modules.dnc.ucenter.Department;
 import org.jeecg.modules.dnc.utils.ValidateUtil;
 
 
 import org.jeecg.modules.dnc.request.ProcessStreamRequest;
 import org.jeecg.modules.dnc.entity.*;
+import org.jeecg.modules.system.entity.MdcProduction;
 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;
 
@@ -43,6 +47,10 @@
     private IDeviceInfoService deviceInfoService;
     @Autowired
     private INcLogInfoService iNcLogInfoService;
+    @Autowired
+    private IPermissionStreamService permissionStreamService;
+    @Autowired
+    private IProcessionDepartmentService processionDepartmentService;
 
     @Override
     @Transactional(rollbackFor = {Exception.class})
@@ -57,6 +65,10 @@
             ExceptionCast.cast(ProcessInfoCode.PROCESS_NAME_NONE);
         if(!ValidateUtil.validateString(stream.getProcessCode()))
             ExceptionCast.cast(ProcessInfoCode.PROCESS_CODE_NONE);
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        String userId = user.getId();
+        if(!ValidateUtil.validateString(userId))
+            ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
         if(ValidateUtil.validateString(stream.getPartsId())) {
             PartsInfo partsInfo = partsInfoService.getById(stream.getPartsId());
             if(partsInfo == null)
@@ -93,10 +105,22 @@
         boolean b = super.save(stream);
         if(!b)
             ExceptionCast.cast(CommonCode.FAIL);
-        ProcessInfo processInfo = new ProcessInfo();
-        processInfo.setProcessName(stream.getProcessName());
-        processInfo.setDescription(stream.getDescription());
-        return processInfoService.addOrEdit(processInfo);
+//        ProcessInfo processInfo = new ProcessInfo();
+//        processInfo.setProcessName(stream.getProcessName());
+//        processInfo.setDescription(stream.getDescription());
+//        boolean processInfoB= processInfoService.addOrEdit(processInfo);
+//        if(!processInfoB)
+//            ExceptionCast.cast(CommonCode.FAIL);
+        //娣诲姞鏉冮檺楠岃瘉
+        PermissionStream permissionStream = new PermissionStream();
+        permissionStream.setUserId(userId);
+        permissionStream.setProductId(stream.getProductId());
+        permissionStream.setComponentId(stream.getComponentId());
+        if (StrUtil.isNotEmpty(stream.getPartsId())){
+            permissionStream.setPartsId(stream.getPartsId());
+        }
+        permissionStream.setProcessId(stream.getProcessId());
+        return permissionStreamService.save(permissionStream);
     }
 
     @Override
@@ -223,4 +247,113 @@
             ExceptionCast.cast(ProcessInfoCode.PROCESS_NOT_EXIST);
         return list;
     }
+
+    @Override
+    public List<ProcessStream> getByuserPerms(String userId){
+        if(!ValidateUtil.validateString(userId))
+            return Collections.emptyList();
+        return super.getBaseMapper().getByUserPerms(userId);
+    }
+
+    @Override
+    public List<ProcessStream> getByuserPerms(String userId,String queryParam){
+        if(!ValidateUtil.validateString(userId))
+            return Collections.emptyList();
+        if(!ValidateUtil.validateString(queryParam))
+            return Collections.emptyList();
+        LambdaQueryWrapper<ProcessStream> queryWrapper = Wrappers.lambdaQuery();
+        if(ValidateUtil.validateString(queryParam)) {
+            queryWrapper.and(wrapper->wrapper.like(ProcessStream::getProcessName, queryParam)
+                    .or()
+                    .like(ProcessStream::getProcessName, queryParam));
+        }
+        queryWrapper.orderByAsc(ProcessStream::getCreateTime);
+        return super.list(queryWrapper);
+    }
+
+    @Override
+    @Transactional(rollbackFor = {Exception.class})
+    public boolean assignAddDepart(ProcessStream processStream, Collection<MdcProduction> departmentList) {
+        if(processStream == null || departmentList == null || departmentList.isEmpty())
+            ExceptionCast.cast(CommonCode.INVALID_PARAM);
+        List<ProcessionDepartment> processionDepartmentList = new ArrayList<>();
+        List<PermissionStream> permissionStreamList = new ArrayList<>();
+        departmentList.forEach(item -> {
+            ProcessionDepartment en = processionDepartmentService.getByProcessIdAndDepartId(processStream.getProcessId(), item.getId());
+            if(en == null) {
+                en = new ProcessionDepartment();
+                en.setDepartId(item.getId());
+                en.setProcessId(processStream.getProcessId());
+                processionDepartmentList.add(en);
+            }
+            PermissionStream stream = permissionStreamService.getByProcessIdAndDepartId(processStream.getProductId(), processStream.getComponentId(), processStream.getPartsId(),processStream.getProcessId(),item.getId());
+            if(stream == null) {
+                stream = new PermissionStream();
+                stream.setDepartId(item.getId());
+                stream.setProductId(processStream.getProductId());
+                stream.setComponentId(processStream.getComponentId());
+                stream.setPartsId(processStream.getPartsId());
+                stream.setProcessId(processStream.getProcessId());
+                permissionStreamList.add(stream);
+            }
+        });
+        if(!processionDepartmentList.isEmpty()) {
+            boolean b = processionDepartmentService.saveBatch(processionDepartmentList);
+            if(!b) {
+                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
+            }
+        }
+        if(!permissionStreamList.isEmpty()) {
+            boolean b = permissionStreamService.saveBatch(permissionStreamList);
+            if(!b) {
+                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public List<ProcessStream> getByComponentIdList(String productId, List<String> componentIds, List<String> partsIds) {
+        return super.baseMapper.findByPartsAndComponents(productId,componentIds,partsIds);
+    }
+
+
+    /**
+     * 鍒嗛厤閮ㄩ棬鏉冮檺
+     * @param processStream
+     * @param departmentList
+     * @return
+     */
+    @Override
+    public boolean assignRemoveDepart(ProcessStream processStream, Collection<MdcProduction> departmentList){
+        if(processStream == null || departmentList == null || departmentList.isEmpty())
+            ExceptionCast.cast(CommonCode.INVALID_PARAM);
+        List<ProcessionDepartment> processionDepartmentList = new ArrayList<>();
+        List<PermissionStream> permissionStreamList = new ArrayList<>();
+        departmentList.forEach(item -> {
+            ProcessionDepartment en = processionDepartmentService.getByProcessIdAndDepartId(processStream.getProcessId(), item.getId());
+            if(en != null) {
+                processionDepartmentList.add(en);
+            }
+            PermissionStream stream = permissionStreamService.getByProcessIdAndDepartId(processStream.getProductId(), processStream.getComponentId(), processStream.getPartsId()
+                    ,processStream.getProcessId(), item.getId());
+            if(stream != null) {
+                permissionStreamList.add(stream);
+            }
+        });
+        if(!processionDepartmentList.isEmpty()) {
+            boolean b = processionDepartmentService.removeByCollection(processionDepartmentList);
+            if(!b) {
+                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
+            }
+        }
+        if(!permissionStreamList.isEmpty()) {
+            boolean b = permissionStreamService.removeByCollection(permissionStreamList);
+            if(!b) {
+                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
+            }
+        }
+        return true;
+    }
+
 }

--
Gitblit v1.9.3