@ -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 )
{
public TableDataInfo list ( SysCustomerVo sysCustomerVo ) {
SysUser curUser = ShiroUtils . getSysUser ( ) ;
Long deptId = curUser . getDeptId ( ) ;
// 通过当前登录人部门id查询该部门下的所有用户
List < SysUser > userList = userService . selectUserByDeptId ( deptId ) ;
// 存储所有的角色键
Set < String > allRoleKeys = new HashSet < > ( ) ;
Long userId = ShiroUtils . getUserId ( ) ;
List < SysUserRole > sysUserRoles = userService . selectUserRoleByUserId ( userId ) ;
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 > allowedFullAccess Creators = new HashSet < > ( ) ;
// 设置可查看的创建者
if ( ! allowedCreators . isEmpty ( ) ) {
sysCustomerVo . setAllowedCreators ( new ArrayList < > ( allowedCreators ) ) ;
if ( allRoleKeys . contains ( "ywyRole" ) ) {
// 业务员只能查看自己添加的客户的所有信息,其他人添加的信息只能查看部分数据
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 ( ) ;
List < SysCustomerVo > list = sysCustomerService . selectSysCustomerList ( sysCustomerVo ) ;
return getDataTable ( list ) ;
}
/ * *
* 导出客户基本信息列表
* /