Browse Source

[fix]系统管理

系统用户新增 通过部门id查询该部门下的所有用户后端方法
修改客户信息分页查询后端接口:通过部门、roleKeys和当前登陆人实现:
1业务员只能查看自己添加的客户的所有信息,其他人添加的信息只能查看部分数据
2业务主管可以查看本部门的所有业务员的客户和自己添加的客户的所有信息,其他人添加的信息只能查看部分数据
3业务经理可以查看本部门的所有业务员、业务主管的客户和自己添加的客户,其他人添加的信息只能查看部分数据
4审批助理或者总经理可以正常显示所有数据
dev
liuxiaoxu 4 weeks ago
parent
commit
d53df11f02
  1. 61
      ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysCustomerController.java
  2. 58
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysCustomerServiceImpl.java
  3. 6
      ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml
  4. 4
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java
  5. 5
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
  6. 8
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
  7. 5
      ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

61
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.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.poi.ExcelUtil; 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.process.general.service.IProcessService;
import com.ruoyi.remind.service.RemindService; import com.ruoyi.remind.service.RemindService;
import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.*;
@ -103,31 +103,58 @@ public class SysCustomerController extends BaseController
@RequiresPermissions("system:customer:list") @RequiresPermissions("system:customer:list")
@PostMapping("/list") @PostMapping("/list")
@ResponseBody @ResponseBody
public TableDataInfo list(SysCustomerVo sysCustomerVo) public TableDataInfo list(SysCustomerVo sysCustomerVo) {
{ SysUser curUser = ShiroUtils.getSysUser();
Long deptId = curUser.getDeptId();
Long userId = ShiroUtils.getUserId();
List<SysUserRole> sysUserRoles = userService.selectUserRoleByUserId(userId); // 通过当前登录人部门id查询该部门下的所有用户
//得到所有的不重复roleKeys List<SysUser> userList = userService.selectUserByDeptId(deptId);
Set<String> roleKeys = sysUserRoles.stream()
.map(SysUserRole::getRoleId) // 存储所有的角色键
.map(roleService::selectRoleById) Set<String> allRoleKeys = new HashSet<>();
.map(SysRole::getRoleKey)
.collect(Collectors.toSet()); for (SysUser sysUser : userList) {
List<SysUserRole> sysUserRoles = userService.selectUserRoleByUserId(sysUser.getUserId());
// 得到所有的不重复roleKeys
Set<String> roleKeys = sysUserRoles.stream()
.map(SysUserRole::getRoleId)
.map(roleService::selectRoleById)
.map(SysRole::getRoleKey)
.collect(Collectors.toSet());
allRoleKeys.addAll(roleKeys);
}
Set<String> allowedCreators = sysCustomerService.getAllowedCreators(roleKeys); Set<String> allowedFullAccessCreators = new HashSet<>();
// 设置可查看的创建者 if (allRoleKeys.contains("ywyRole")) {
if (!allowedCreators.isEmpty()) { // 业务员只能查看自己添加的客户的所有信息,其他人添加的信息只能查看部分数据
sysCustomerVo.setAllowedCreators(new ArrayList<>(allowedCreators)); allowedFullAccessCreators.add(curUser.getLoginName());
}
if (allRoleKeys.contains("ywzgRole")) {
// 业务主管可以查看本部门的所有业务员的客户和自己添加的客户的所有信息,其他人添加的信息只能查看部分数据
List<SysUser> 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<SysUser> 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(); startPage();
List<SysCustomerVo> list = sysCustomerService.selectSysCustomerList(sysCustomerVo); List<SysCustomerVo> list = sysCustomerService.selectSysCustomerList(sysCustomerVo);
return getDataTable(list); return getDataTable(list);
} }
/** /**
* 导出客户基本信息列表 * 导出客户基本信息列表
*/ */

58
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 org.springframework.util.CollectionUtils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* 客户基本信息Service业务层处理 * 客户基本信息Service业务层处理
@ -106,9 +107,40 @@ public class SysCustomerServiceImpl implements ISysCustomerService
Integer pageNum = pageDomain.getPageNum(); Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize(); Integer pageSize = pageDomain.getPageSize();
Page<SysCustomerVo> list = (Page<SysCustomerVo>) sysCustomerMapper.selectSysCustomerList(sysCustomer); Page<SysCustomerVo> list = (Page<SysCustomerVo>) sysCustomerMapper.selectSysCustomerList(sysCustomer);
List<SysCustomerVo> filteredList = new ArrayList<>();
String loginName = ShiroUtils.getLoginName();
if (loginName.equals("gmo_asst01") ||loginName.equals("gmo_gm") ){
filteredList = list;
}else {
List<String> 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<SysCustomerVo> returnList = new Page<>(); Page<SysCustomerVo> returnList = new Page<>();
//PageHelper 仅对第一List分页有效 //PageHelper 仅对第一List分页有效
for(SysCustomerVo sysCustomerVo : list){ for(SysCustomerVo sysCustomerVo : filteredList){
SysUser sysUser = userMapper.selectUserByLoginName(sysCustomerVo.getCreateBy()); SysUser sysUser = userMapper.selectUserByLoginName(sysCustomerVo.getCreateBy());
if (sysUser != null) { if (sysUser != null) {
sysCustomerVo.setCreateBy(sysUser.getUserName()); sysCustomerVo.setCreateBy(sysUser.getUserName());
@ -189,18 +221,18 @@ public class SysCustomerServiceImpl implements ISysCustomerService
@Override @Override
public Set<String> getAllowedCreators(Set<String> roleKeys) { public Set<String> getAllowedCreators(Set<String> roleKeys) {
Set<String> allowedCreators = new HashSet<>(); Set<String> allowedCreators = new HashSet<>();
if (roleKeys.contains("ywyRole")) { // if (roleKeys.contains("ywyRole")) {
allowedCreators.add(ShiroUtils.getLoginName()); // 只能看到自己的数据 // allowedCreators.add(ShiroUtils.getLoginName()); // 只能看到自己的数据
} // }
if (roleKeys.contains("ywzgRole")) { // if (roleKeys.contains("ywzgRole")) {
allowedCreators.add("sales_m2"); // allowedCreators.add("sales_m2");
allowedCreators.add("sales_01"); // allowedCreators.add("sales_01");
} // }
if (roleKeys.contains("ywjlRole")) { // if (roleKeys.contains("ywjlRole")) {
allowedCreators.add("sales_m2"); // allowedCreators.add("sales_m2");
allowedCreators.add("sales_01"); // allowedCreators.add("sales_01");
allowedCreators.add("sales_m1"); // allowedCreators.add("sales_m1");
} // }
return allowedCreators; return allowedCreators;
} }

6
ruoyi-admin/src/main/resources/mapper/system/SysCustomerMapper.xml

@ -122,12 +122,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deliveryAddress != null and deliveryAddress != ''"> and s.delivery_address like concat('%', #{deliveryAddress}, '%')</if> <if test="deliveryAddress != null and deliveryAddress != ''"> and s.delivery_address like concat('%', #{deliveryAddress}, '%')</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and s.create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if> <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and s.create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
<if test="customerSign != null and customerSign != ''"> and s.customer_sign = #{customerSign}</if> <if test="customerSign != null and customerSign != ''"> and s.customer_sign = #{customerSign}</if>
<!-- 添加权限控制逻辑 -->
<if test="allowedCreators != null and !allowedCreators.isEmpty()">
and s.create_by in (<foreach item="item" index="index" collection="allowedCreators" open="" close="" separator=",">
#{item}
</foreach>)
</if>
</where> </where>
order by s.audit_status asc, s.create_time desc order by s.audit_status asc, s.create_time desc
</select> </select>

4
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java

@ -172,4 +172,8 @@ public interface SysUserMapper
List<SysUser> selectUserAll() throws Exception; List<SysUser> selectUserAll() throws Exception;
/**
* 通过部门id查询该部门下的所有用户
* */
List<SysUser> selectUserByDeptId(Long deptId);
} }

5
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java

@ -221,4 +221,9 @@ public interface ISysUserService
List<SysUser> selectRoleToUserList(String roleKeys); List<SysUser> selectRoleToUserList(String roleKeys);
public List<SysUser> selectUserAll() throws Exception; public List<SysUser> selectUserAll() throws Exception;
/**
* 通过部门id查询该部门下的所有用户
* */
List<SysUser> selectUserByDeptId(Long deptId);
} }

8
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@ -550,4 +550,12 @@ public class SysUserServiceImpl implements ISysUserService
public List<SysUser> selectUserAll() throws Exception { public List<SysUser> selectUserAll() throws Exception {
return userMapper.selectUserAll(); return userMapper.selectUserAll();
} }
/**
* 通过部门id查询该部门下的所有用户
* */
@Override
public List<SysUser> selectUserByDeptId(Long deptId) {
return userMapper.selectUserByDeptId(deptId);
}
} }

5
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@ -273,4 +273,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectUserVo"/> <include refid="selectUserVo"/>
where u.del_flag = '0' where u.del_flag = '0'
</select> </select>
<select id="selectUserByDeptId" parameterType="Long" resultMap="SysUserResult">
select user_id,dept_id,login_name,user_name from sys_user where dept_id = #{deptId} and del_flag = '0'
</select>
</mapper> </mapper>
Loading…
Cancel
Save