From d51a8cfa10c34d9c1e7d6b4726d31e75ecee5dc6 Mon Sep 17 00:00:00 2001
From: phpcjl <phpcjl@gmail.com>
Date: 星期五, 20 十二月 2024 18:32:03 +0800
Subject: [PATCH] 1

---
 ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java |   41 ++++++++++++++++++++++++++++++++++-------
 1 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
index f484336..3f9f7e9 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -6,6 +6,7 @@
 import com.ruoyi.common.core.utils.SpringUtils;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.datascope.annotation.DataScope;
+import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.common.security.utils.SecurityUtils;
 import com.ruoyi.system.api.domain.SysDept;
 import com.ruoyi.system.api.domain.SysRole;
@@ -14,9 +15,11 @@
 import com.ruoyi.system.mapper.SysDeptMapper;
 import com.ruoyi.system.mapper.SysRoleMapper;
 import com.ruoyi.system.service.ISysDeptService;
+import com.ruoyi.system.service.ISysUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -35,6 +38,15 @@
 
     @Autowired
     private SysRoleMapper roleMapper;
+    
+    @Resource
+    private TokenService tokenService;
+    
+    @Resource
+    private ISysUserService sysUserService;
+    
+    
+    
 
     /**
      * 查询部门管理数据
@@ -44,8 +56,12 @@
      */
     @Override
     @DataScope(deptAlias = "d")
-    public List<SysDept> selectDeptList(SysDept dept)
-    {
+    public List<SysDept> selectDeptList(SysDept dept) {
+        Long userid = tokenService.getLoginUser().getUserid();
+        SysUser sysUser = sysUserService.getById(userid);
+        if(sysUser.getRoleType() == 2){
+            dept.setShopId(sysUser.getObjectId());
+        }
         return deptMapper.selectDeptList(dept);
     }
 
@@ -214,11 +230,17 @@
     {
         SysDept info = deptMapper.selectDeptById(dept.getParentId());
         // 如果父节点不为正常状态,则不允许新增子节点
-        if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
+        if (null != info && !UserConstants.DEPT_NORMAL.equals(info.getStatus()))
         {
             throw new ServiceException("部门停用,不允许新增");
         }
         dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
+        //判断店铺数据
+        Long userid = tokenService.getLoginUser().getUserid();
+        SysUser sysUser = sysUserService.getById(userid);
+        if(sysUser.getRoleType() == 2){
+            dept.setShopId(sysUser.getObjectId());
+        }
         return deptMapper.insertDept(dept);
     }
 
@@ -233,12 +255,17 @@
     {
         SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
         SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
-        if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
-        {
+        if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) {
             String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
             String oldAncestors = oldDept.getAncestors();
             dept.setAncestors(newAncestors);
             updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
+        }
+        //判断店铺数据
+        Long userid = tokenService.getLoginUser().getUserid();
+        SysUser sysUser = sysUserService.getById(userid);
+        if(sysUser.getRoleType() == 2){
+            dept.setShopId(sysUser.getObjectId());
         }
         int result = deptMapper.updateDept(dept);
         if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
@@ -320,7 +347,7 @@
         Iterator<SysDept> it = list.iterator();
         while (it.hasNext())
         {
-            SysDept n = (SysDept) it.next();
+            SysDept n = it.next();
             if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue())
             {
                 tlist.add(n);
@@ -334,6 +361,6 @@
      */
     private boolean hasChild(List<SysDept> list, SysDept t)
     {
-        return getChildList(list, t).size() > 0 ? true : false;
+        return getChildList(list, t).size() > 0;
     }
 }

--
Gitblit v1.7.1