无关风月
2025-02-28 2f8e70ad2884d2b6b7443dfae0af11ae9cfc8b99
manage/src/main/java/com/jilongda/manage/authority/controller/SecUserController.java
@@ -26,6 +26,8 @@
import com.jilongda.manage.authority.service.SecUserService;
import com.jilongda.manage.authority.vo.SecResourceVO;
import com.jilongda.manage.authority.vo.SecUsersVO;
import com.jilongda.manage.model.TOptometrist;
import com.jilongda.manage.query.TOptometristQuery;
import com.jilongda.manage.utils.LoginInfoUtil;
import com.jilongda.manage.utils.UserUtil;
import com.jilongda.common.basic.ApiResult;
@@ -81,19 +83,17 @@
    private final PasswordEncoder passwordEncoder;
    private final UserUtil userUtil;
    private final SecUserRoleService secUserRoleService;
    private final TDeptService deptService;
    private final LoginInfoUtil loginInfoUtil;
    private final RedisAutoTemplate redisAutoTemplate;
    @Autowired
    public SecUserController(SecUserService secUserService, SecRoleService secRoleService, SecResourcesService secResourcesService, PasswordEncoder passwordEncoder, UserUtil userUtil, SecUserRoleService secUserRoleService, TDeptService deptService, LoginInfoUtil loginInfoUtil, RedisAutoTemplate redisAutoTemplate) {
    public SecUserController(SecUserService secUserService, SecRoleService secRoleService, SecResourcesService secResourcesService, PasswordEncoder passwordEncoder, UserUtil userUtil, SecUserRoleService secUserRoleService, LoginInfoUtil loginInfoUtil, RedisAutoTemplate redisAutoTemplate) {
        this.secUserService = secUserService;
        this.secRoleService = secRoleService;
        this.secResourcesService = secResourcesService;
        this.passwordEncoder = passwordEncoder;
        this.userUtil = userUtil;
        this.secUserRoleService = secUserRoleService;
        this.deptService = deptService;
        this.loginInfoUtil = loginInfoUtil;
        this.redisAutoTemplate = redisAutoTemplate;
    }
@@ -166,6 +166,14 @@
    public ApiResult<String> addOrUpdateUser(@Validated @RequestBody SecUserDTO dto) {
        secUserService.addOrUpdateUser(dto);
        return ApiResult.success();
    }
    @ApiOperation(value = "通过门店id查询验光师列表")
    @GetMapping(value = "/queryListByStoreId")
    public ApiResult<List<SecUser>> queryListByStoreId(@RequestParam Integer storeId) {
        List<SecUser> secUsers = secUserService.list(Wrappers.lambdaQuery(SecUser.class)
                .eq(SecUser::getStoreId,storeId));
        return ApiResult.success(secUsers);
    }
    @OperationLog(operType = "重置", operDesc = "重置密码", operModul = "用户")
@@ -317,89 +325,6 @@
                e.printStackTrace();
            }
        }
    }
    /**
     * 人员新增列表
     */
    @ApiOperation(value = "人员新增列表",notes = "type 1=部门,2=用户")
    @GetMapping("/userAddList")
    public ApiResult userAddList(@RequestParam(required = false) String name)
    {
        UserAddListVO userAddListVO = new UserAddListVO();
        // 获取当前用户所在部门
        SecUser loginUser = loginInfoUtil.getLoginUser();
        Long deptId = loginUser.getDeptId();
        List<TDept> deptList = new ArrayList<>();
        List<SecUser> userList = new ArrayList<>();
        List<UserLevelVO> userLevelVOS = new ArrayList<>();
        if(!loginUser.isAdmin()){
            userList = secUserService.selectListByNamePhoneDeptId(name,deptId);
            if(CollectionUtils.isEmpty(userList)){
                return ApiResult.success(userAddListVO);
            }
            TDept dept = deptService.getById(deptId);
            UserLevelVO userLevelVO = new UserLevelVO();
            List<UserLevelVO> children = new ArrayList<>();
            for (SecUser user : userList) {
                UserLevelVO userLevelVO1 = new UserLevelVO();
                userLevelVO1.setKey(user.getId());
                userLevelVO1.setTitle(user.getNickName());
                userLevelVO1.setAvatar(user.getAvatarUrl());
                userLevelVO1.setFlag(true);
                userLevelVO1.setValue(CodeGenerateUtils.generateVolumeSn());
                children.add(userLevelVO1);
            }
            userLevelVO.setChildren(children);
            userLevelVO.setKey(dept.getId());
            userLevelVO.setTitle(dept.getDeptName());
            userLevelVO.setValue(CodeGenerateUtils.generateVolumeSn());
            userLevelVOS.add(userLevelVO);
        }else {
            // 查询符合要求部门id
            deptList = deptService.userAddListByDeptNameDeptIds(name,null);
            List<Long> deptIds = deptList.stream().map(TDept::getId).collect(Collectors.toList());
            userList = secUserService.selectListByNamePhoneDeptIds(name,null);
            deptIds.addAll(userList.stream().map(SecUser::getDeptId).collect(Collectors.toList()));
            // 查询部门
            deptList = deptService.userAddListByDeptNameDeptIds(null,deptIds);
            if(CollectionUtils.isEmpty(deptList)){
                return ApiResult.success(userAddListVO);
            }
            // 查询用户
            userList = secUserService.selectListByNamePhoneDeptIds(null,deptIds);
            for (TDept dept : deptList) {
                List<SecUser> users;
                if(StringUtils.hasLength(name) && !dept.getDeptName().contains(name)){
                    users = userList.stream().filter(e -> dept.getId().equals(e.getDeptId())
                            && (((StringUtils.hasLength(e.getNickName()) && e.getNickName().contains(name)))
                            || (StringUtils.hasLength(e.getPhone()) && e.getPhone().contains(name)))).collect(Collectors.toList());
                }else {
                    users = userList.stream().filter(e -> dept.getId().equals(e.getDeptId())).collect(Collectors.toList());
                }
                UserLevelVO userLevelVO = new UserLevelVO();
                List<UserLevelVO> children = new ArrayList<>();
                for (SecUser user : users) {
                    UserLevelVO userLevelVO1 = new UserLevelVO();
                    userLevelVO1.setKey(user.getId());
                    userLevelVO1.setTitle(user.getNickName());
                    userLevelVO1.setAvatar(user.getAvatarUrl());
                    userLevelVO1.setFlag(true);
                    userLevelVO1.setValue(CodeGenerateUtils.generateVolumeSn());
                    children.add(userLevelVO1);
                }
                userLevelVO.setChildren(children);
                userLevelVO.setKey(dept.getId());
                userLevelVO.setTitle(dept.getDeptName());
                userLevelVO.setValue(CodeGenerateUtils.generateVolumeSn());
                userLevelVOS.add(userLevelVO);
            }
        }
        userAddListVO.setUserLevelVOS(userLevelVOS);
        return ApiResult.success(userAddListVO);
    }
    @ApiOperation(value = "用户导入")