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