xiaoyong931011
2022-06-10 93e281b3cc60c8d24a0ed5547d3d399c03f9bab6
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/UserServiceImpl.java
@@ -12,10 +12,7 @@
import com.xcong.farmer.cms.modules.system.mapper.*;
import com.xcong.farmer.cms.modules.system.service.IUserService;
import com.xcong.farmer.cms.modules.system.util.LoginUserUtil;
import com.xcong.farmer.cms.modules.system.vo.AdminRoleVo;
import com.xcong.farmer.cms.modules.system.vo.AdminSeeUserInfoVo;
import com.xcong.farmer.cms.modules.system.vo.AdminUserMenuVo;
import com.xcong.farmer.cms.modules.system.vo.AdminUserVo;
import com.xcong.farmer.cms.modules.system.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.util.StrUtil;
@@ -46,9 +43,12 @@
        UserEntity userlogin = LoginUserUtil.getLoginUser();
        Page<AdminUserVo> page = new Page<>(adminUserDto.getPageNum(), adminUserDto.getPageSize());
        UserEntity userEntity = new UserEntity();
        long belongId = userlogin.getBelongId() == null ? 0L : userlogin.getBelongId();
        if(belongId > 0L){
        long belongId = userlogin.getBelongId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getBelongId();
        if(belongId > UserEntity.USER_BELONG_TOP){
            userEntity.setBelongId(belongId);
            userEntity.setRoleName(RoleEntity.ROLE_ADMIN_NAME);
        }else if(belongId == UserEntity.USER_BELONG_TOP){
            userEntity.setRoleName(RoleEntity.ROLE_SUPER_NAME);
        }
        if(StrUtil.isNotEmpty(adminUserDto.getUsername())){
            userEntity.setUsername(adminUserDto.getUsername());
@@ -85,6 +85,13 @@
        if(StrUtil.isEmpty(username)){
            return Result.fail("请输入用户名");
        }
        QueryWrapper<UserEntity> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("username",username);
//        objectQueryWrapper.eq("belong_id",userlogin.getBelongId());
        List<UserEntity> userEntities = this.baseMapper.selectList(objectQueryWrapper);
        if(CollUtil.isNotEmpty(userEntities)){
            return Result.fail("用户名重复");
        }
        String roleIds = adminAddUserDto.getRoleIds();
        if(StrUtil.isEmpty(roleIds)){
            return Result.fail("请选择用户角色");
@@ -93,8 +100,8 @@
        if(StrUtil.isEmpty(phone)){
            return Result.fail("请输入联系电话");
        }
        Long belongId = adminAddUserDto.getBelongId() == null ? 0L:adminAddUserDto.getBelongId();
        if(belongId == 0L){
        Long belongId = adminAddUserDto.getBelongId() == null ? UserEntity.USER_BELONG_TOP:adminAddUserDto.getBelongId();
        if(belongId == UserEntity.USER_BELONG_TOP){
            return Result.fail("请选择所属公司");
        }
        UserEntity userEntity = new UserEntity();
@@ -301,6 +308,20 @@
            }
        }
        if(CollUtil.isNotEmpty(adminUserMenuVos)){
            for(AdminUserMenuVo adminUserMenuVo : adminUserMenuVos){
                List<AdminUserMenuVo> child = adminUserMenuVo.getChild();
                if(CollUtil.isNotEmpty(child)){
                    List<Long> menuIdChilds = new ArrayList<>();
                    for(AdminUserMenuVo adminUserMenuVoChild : child){
                        Long id = adminUserMenuVoChild.getId();
                        menuIdChilds.add(id);
                    }
                    List<AdminUserMenuVo> adminUserMenuVoByOrderNum = menuMapper.selectAdminUserMenuVoOrderByOrderNum(menuIdChilds);
                    adminUserMenuVo.setChild(adminUserMenuVoByOrderNum);
                }
            }
        }
        return Result.ok(adminUserMenuVos);
    }
@@ -350,6 +371,23 @@
        return Result.ok("修改成功");
    }
    @Override
    public Result userInfo() {
        UserEntity loginUser = LoginUserUtil.getLoginUser();
        Long id = loginUser.getId();
        UserEntity userEntity = this.baseMapper.selectById(id);
        if(ObjectUtil.isEmpty(userEntity)){
            return Result.fail("用户不存在");
        }
        AdminUserInfoVo adminUserInfoVo = new AdminUserInfoVo();
        adminUserInfoVo.setId(userEntity.getId());
        adminUserInfoVo.setUsername(userEntity.getUsername());
        adminUserInfoVo.setNickname(userEntity.getNickname());
        adminUserInfoVo.setPhone(userEntity.getPhone());
        adminUserInfoVo.setEmail(userEntity.getEmail());
        return Result.ok(adminUserInfoVo);
    }
    private void saveUserRole(String roleIds,Long userId) {
        if (StrUtil.isNotEmpty(roleIds)) {
            String[] roleIdList = roleIds.split(StringPool.COMMA);