1. add findUserByIds rpc

main
lyp 1 year ago
parent 8a10e0f9dc
commit bebfd9d122

@ -1,11 +1,18 @@
package com.luoo.comment.client;
import api.Result;
import client.vo.SimpleUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@FeignClient("luoo-user")
public interface UserClient {
//todo 根据用户 IDs 获取用户昵称集合
@GetMapping("/findUserByIds")
Result<List<SimpleUser>> findUserByIds(List<String> ids);
}

@ -24,8 +24,6 @@ public class BaseExceptionHandler {
@ExceptionHandler(value = AuthorityLoginException.class)
@ResponseBody
public Result<String> error(AuthorityLoginException e) {
log.info("业务错误:{}", e.getMessage());
StatusCode statusCode = null == e.getCodeEnum() ? StatusCode.MUSIC_COMMON_FAILED : e.getCodeEnum();
return Result.failed(statusCode, e.getMessage());
return Result.unauthorized(null);
}
}

@ -0,0 +1,11 @@
package client.vo;
import lombok.Data;
@Data
public class SimpleUser {
private String userId;
private String nickName;
}

@ -1,27 +1,22 @@
package com.luoo.user.controller;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.luoo.user.service.UserCollectService;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.Result;
import client.vo.SimpleUser;
import com.luoo.user.service.UserCollectService;
import com.luoo.user.service.UserService;
import dto.UserLoginDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import util.JwtUtil;
import java.util.List;
@Api(tags = "UserCollectController")
@RestController
@RequestMapping("/userCollect")
@ -30,6 +25,8 @@ public class UserCollectController {
private JwtUtil jwtUtil;
@Autowired
private UserCollectService userCollectService;
@Autowired
private UserService userService;
@ApiOperation(value = "1.收藏/喜欢")
@ApiImplicitParams({ @ApiImplicitParam(name = "objectId", value = "收藏/喜欢的id此处为歌曲/期刊id", required = true),
@ -57,4 +54,12 @@ public class UserCollectController {
collectType);
return Result.success();
}
@ApiOperation(value = "根据 IDs 获取用户简要信息")
@GetMapping("/findUserByIds")
public Result<List<SimpleUser>> findUserByIds(@RequestBody List<String> ids) {
List<SimpleUser> userByIds = userService.findUserByIds(ids);
return Result.success(userByIds);
}
}

@ -1,12 +1,13 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import com.luoo.user.pojo.User;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* 访
* @author Administrator
@ -28,4 +29,7 @@ public interface UserDao extends JpaRepository<User,String>,JpaSpecificationExec
public User findByLoginname(String loginname);
public long countByNickname(String nickName);
@Query("SELECT * FROM tb_user m WHERE m.id IN ?1")
List<User> findUserByIds(List<String> ids);
}

@ -1,12 +1,12 @@
package com.luoo.user.pojo;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import client.vo.SimpleUser;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
/**
*
@ -40,4 +40,11 @@ public class User implements Serializable{
private Integer followcount;//关注数
//private String deviceId;//设备id
//private String deviceBrand;//设备品牌
public SimpleUser converSimpleUser(){
SimpleUser simpleUser = new SimpleUser();
simpleUser.setUserId(this.getId());
simpleUser.setNickName(this.nickname);
return simpleUser;
}
}

@ -1,14 +1,12 @@
package com.luoo.user.service;
import java.util.*;
import java.util.concurrent.TimeUnit;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.servlet.http.HttpServletRequest;
import client.vo.SimpleUser;
import com.luoo.user.dao.UserDao;
import com.luoo.user.dao.UserInfoDao;
import com.luoo.user.pojo.User;
import com.luoo.user.util.NickNameUtil;
import constants.Constants;
import dto.UserLoginDto;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
@ -18,19 +16,20 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import util.IdWorker;
import constants.Constants;
import com.luoo.user.dao.UserDao;
import com.luoo.user.dao.UserInfoDao;
import com.luoo.user.pojo.User;
import com.luoo.user.util.NickNameUtil;
import dto.UserLoginDto;
import util.JwtUtil;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
*
*
@ -299,4 +298,13 @@ public class UserService {
public long countByNickName(String nickName) {
return userDao.countByNickname(nickName);
}
public List<SimpleUser> findUserByIds(List<String> ids) {
List<User> userByIds = userDao.findUserByIds(ids);
if (CollectionUtils.isEmpty(userByIds)){
return new ArrayList<>();
}
return userByIds.stream().map(User::converSimpleUser).collect(Collectors.toList());
}
}

Loading…
Cancel
Save