From d53df11f02e5a3d741e3ffbd0a07e7333a1a5b08 Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Thu, 31 Oct 2024 16:40:24 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=94=A8=E6=88=B7=E6=96=B0=E5=A2=9E=20?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E9=83=A8=E9=97=A8id=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=AF=A5=E9=83=A8=E9=97=A8=E4=B8=8B=E7=9A=84=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8E=E7=AB=AF=E6=96=B9=E6=B3=95=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=A2=E6=88=B7=E4=BF=A1=E6=81=AF=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=9A=E9=80=9A=E8=BF=87=E9=83=A8=E9=97=A8=E3=80=81roleKeys?= =?UTF-8?q?=E5=92=8C=E5=BD=93=E5=89=8D=E7=99=BB=E9=99=86=E4=BA=BA=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=EF=BC=9A=201=E4=B8=9A=E5=8A=A1=E5=91=98=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E6=9F=A5=E7=9C=8B=E8=87=AA=E5=B7=B1=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=9A=84=E5=AE=A2=E6=88=B7=E7=9A=84=E6=89=80=E6=9C=89=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=85=B6=E4=BB=96=E4=BA=BA=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=9A=84=E4=BF=A1=E6=81=AF=E5=8F=AA=E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=AA=E8=83=BD=E6=9F=A5=E7=9C=8B=E9=83=A8=E5=88=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=204=E5=AE=A1=E6=89=B9=E5=8A=A9=E7=90=86=E6=88=96?= =?UTF-8?q?=E8=80=85=E6=80=BB=E7=BB=8F=E7=90=86=E5=8F=AF=E4=BB=A5=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E6=98=BE=E7=A4=BA=E6=89=80=E6=9C=89=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SysCustomerController.java | 61 +++++++++++++------ .../service/impl/SysCustomerServiceImpl.java | 58 ++++++++++++++---- .../mapper/system/SysCustomerMapper.xml | 6 -- .../ruoyi/system/mapper/SysUserMapper.java | 4 ++ .../ruoyi/system/service/ISysUserService.java | 5 ++ .../service/impl/SysUserServiceImpl.java | 8 +++ .../resources/mapper/system/SysUserMapper.xml | 5 ++ 7 files changed, 111 insertions(+), 36 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerController.java b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerController.java index 42f60f60..3be9b1be 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerController.java @@ -17,10 +17,10 @@ import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.poi.ExcelUtil; -import com.ruoyi.framework.web.domain.server.Sys; import com.ruoyi.process.general.service.IProcessService; import com.ruoyi.remind.service.RemindService; import com.ruoyi.system.domain.*; @@ -103,31 +103,58 @@ public class SysCustomerController extends BaseController @RequiresPermissions("system:customer:list") @PostMapping("/list") @ResponseBody - public TableDataInfo list(SysCustomerVo sysCustomerVo) - { - - Long userId = ShiroUtils.getUserId(); - List sysUserRoles = userService.selectUserRoleByUserId(userId); - //得到所有的不重复roleKeys - Set roleKeys = sysUserRoles.stream() - .map(SysUserRole::getRoleId) - .map(roleService::selectRoleById) - .map(SysRole::getRoleKey) - .collect(Collectors.toSet()); + public TableDataInfo list(SysCustomerVo sysCustomerVo) { + SysUser curUser = ShiroUtils.getSysUser(); + Long deptId = curUser.getDeptId(); + + // 通过当前登录人部门id查询该部门下的所有用户 + List userList = userService.selectUserByDeptId(deptId); + + // 存储所有的角色键 + Set allRoleKeys = new HashSet<>(); + + for (SysUser sysUser : userList) { + List sysUserRoles = userService.selectUserRoleByUserId(sysUser.getUserId()); + // 得到所有的不重复roleKeys + Set roleKeys = sysUserRoles.stream() + .map(SysUserRole::getRoleId) + .map(roleService::selectRoleById) + .map(SysRole::getRoleKey) + .collect(Collectors.toSet()); + allRoleKeys.addAll(roleKeys); + } - Set allowedCreators = sysCustomerService.getAllowedCreators(roleKeys); + Set allowedFullAccessCreators = new HashSet<>(); - // 设置可查看的创建者 - if (!allowedCreators.isEmpty()) { - sysCustomerVo.setAllowedCreators(new ArrayList<>(allowedCreators)); + if (allRoleKeys.contains("ywyRole")) { + // 业务员只能查看自己添加的客户的所有信息,其他人添加的信息只能查看部分数据 + allowedFullAccessCreators.add(curUser.getLoginName()); + } + if (allRoleKeys.contains("ywzgRole")) { + // 业务主管可以查看本部门的所有业务员的客户和自己添加的客户的所有信息,其他人添加的信息只能查看部分数据 + List businessUsers = userList.stream() + .filter(user -> allRoleKeys.contains("ywyRole")) + .collect(Collectors.toList()); + businessUsers.forEach(user -> allowedFullAccessCreators.add(user.getLoginName())); + allowedFullAccessCreators.add(curUser.getLoginName()); } + if (allRoleKeys.contains("ywjlRole")) { + // 业务经理可以查看本部门的所有业务员、业务主管的客户和自己添加的客户,其他人添加的信息只能查看部分数据 + List businessUsersAndManagers = userList.stream() + .filter(user -> allRoleKeys.contains("ywyRole") || allRoleKeys.contains("ywzgRole")) + .collect(Collectors.toList()); + businessUsersAndManagers.forEach(user -> allowedFullAccessCreators.add(user.getLoginName())); + allowedFullAccessCreators.add(curUser.getLoginName()); + } + + sysCustomerVo.setAllowedCreators(new ArrayList<>(allowedFullAccessCreators)); startPage(); List list = sysCustomerService.selectSysCustomerList(sysCustomerVo); - return getDataTable(list); } + /** * 导出客户基本信息列表 */ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java index 2646ec22..5ecfa13b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java @@ -36,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.*; +import java.util.stream.Collectors; /** * 客户基本信息Service业务层处理 @@ -106,9 +107,40 @@ public class SysCustomerServiceImpl implements ISysCustomerService Integer pageNum = pageDomain.getPageNum(); Integer pageSize = pageDomain.getPageSize(); Page list = (Page) sysCustomerMapper.selectSysCustomerList(sysCustomer); + List filteredList = new ArrayList<>(); + String loginName = ShiroUtils.getLoginName(); + if (loginName.equals("gmo_asst01") ||loginName.equals("gmo_gm") ){ + filteredList = list; + }else { + List allowedFullAccessCreators = sysCustomer.getAllowedCreators(); + + // 过滤结果集 + filteredList = list.stream() + .map(item -> { + if (allowedFullAccessCreators.contains(item.getApplyUser()) || item.getApplyUser().equals(loginName)) { + return item; // 返回完整的对象 + } else { + SysCustomerVo filteredItem = new SysCustomerVo(); + filteredItem.setId(item.getId()); // 保留 ID + filteredItem.setEnterpriseCode(item.getEnterpriseCode()); + filteredItem.setEnterpriseName(item.getEnterpriseName()); + filteredItem.setTaskId(item.getTaskId()); + filteredItem.setTaskName(item.getTaskName()); + filteredItem.setInstanceTypeName(item.getInstanceTypeName()); + filteredItem.setInstanceType(item.getInstanceType()); + filteredItem.setApplyUser(item.getApplyUser()); + filteredItem.setTaskStatus(item.getTaskStatus()); + filteredItem.setAuditStatus(item.getAuditStatus()); + return filteredItem; // 只返回 enterprise_code 、enterprise_name 和 审批相关数据 + } + }) + .collect(Collectors.toList()); + } + + Page returnList = new Page<>(); //PageHelper 仅对第一List分页有效 - for(SysCustomerVo sysCustomerVo : list){ + for(SysCustomerVo sysCustomerVo : filteredList){ SysUser sysUser = userMapper.selectUserByLoginName(sysCustomerVo.getCreateBy()); if (sysUser != null) { sysCustomerVo.setCreateBy(sysUser.getUserName()); @@ -189,18 +221,18 @@ public class SysCustomerServiceImpl implements ISysCustomerService @Override public Set getAllowedCreators(Set roleKeys) { Set allowedCreators = new HashSet<>(); - if (roleKeys.contains("ywyRole")) { - allowedCreators.add(ShiroUtils.getLoginName()); // 只能看到自己的数据 - } - if (roleKeys.contains("ywzgRole")) { - allowedCreators.add("sales_m2"); - allowedCreators.add("sales_01"); - } - if (roleKeys.contains("ywjlRole")) { - allowedCreators.add("sales_m2"); - allowedCreators.add("sales_01"); - allowedCreators.add("sales_m1"); - } +// if (roleKeys.contains("ywyRole")) { +// allowedCreators.add(ShiroUtils.getLoginName()); // 只能看到自己的数据 +// } +// if (roleKeys.contains("ywzgRole")) { +// allowedCreators.add("sales_m2"); +// allowedCreators.add("sales_01"); +// } +// if (roleKeys.contains("ywjlRole")) { +// allowedCreators.add("sales_m2"); +// allowedCreators.add("sales_01"); +// allowedCreators.add("sales_m1"); +// } return allowedCreators; } diff --git a/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml b/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml index 09f9cf11..bf12d201 100644 --- a/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml @@ -122,12 +122,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and s.delivery_address like concat('%', #{deliveryAddress}, '%') and s.create_time between #{params.beginCreateTime} and #{params.endCreateTime} and s.customer_sign = #{customerSign} - - - and s.create_by in ( - #{item} - ) - order by s.audit_status asc, s.create_time desc diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java index c09a97c3..30684951 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java @@ -172,4 +172,8 @@ public interface SysUserMapper List selectUserAll() throws Exception; + /** + * 通过部门id查询该部门下的所有用户 + * */ + List selectUserByDeptId(Long deptId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java index 22f87dd8..1a8d3ddc 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java @@ -221,4 +221,9 @@ public interface ISysUserService List selectRoleToUserList(String roleKeys); public List selectUserAll() throws Exception; + + /** + * 通过部门id查询该部门下的所有用户 + * */ + List selectUserByDeptId(Long deptId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index 557c0590..5347e490 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -550,4 +550,12 @@ public class SysUserServiceImpl implements ISysUserService public List selectUserAll() throws Exception { return userMapper.selectUserAll(); } + + /** + * 通过部门id查询该部门下的所有用户 + * */ + @Override + public List selectUserByDeptId(Long deptId) { + return userMapper.selectUserByDeptId(deptId); + } } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index 470a3630..233e2598 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -273,4 +273,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where u.del_flag = '0' + + + \ No newline at end of file