Commit 5ae97a31 by chamberone

feat: 添加用户登录和获取用户接口

1 parent baf13f7e
package com.dituhui.pea.pojo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
@Data
public class UserLoginDTO {
private String account;
@JsonIgnore
private String password;
private String nickname;
private String email;
private String phone;
private String birthday;
private String region;
private Integer sex;
private String avatar;
private String wechat;
private String token;
}
package com.dituhui.pea.user; package com.dituhui.pea.user;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.enums.ThirdPartyEnum; import com.dituhui.pea.enums.ThirdPartyEnum;
import com.dituhui.pea.pojo.ThirdUserInfo; import com.dituhui.pea.pojo.ThirdUserInfo;
import com.dituhui.pea.pojo.UserInfo; import com.dituhui.pea.pojo.UserInfo;
import com.dituhui.pea.pojo.UserLoginDTO;
import com.dituhui.pea.pojo.WebResult; import com.dituhui.pea.pojo.WebResult;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -16,6 +19,12 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -16,6 +19,12 @@ import org.springframework.web.bind.annotation.RequestParam;
*/ */
@FeignClient(value = "user") @FeignClient(value = "user")
public interface IUser { public interface IUser {
@RequestMapping(value = "/user/login", method = RequestMethod.POST)
public Result<?> userLogin(@RequestBody UserLoginDTO user);
@RequestMapping(value = "/user/userInfo", method = RequestMethod.GET)
public Result<?> getUserInfo(@RequestHeader(name="Authorization", required = true) String authorization);
/** /**
* 获取当前登陆用户信息 * 获取当前登陆用户信息
......
...@@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RestController;
/** /**
* 角色控制层 * 角色控制层
* @author zl
*/ */
@RestController @RestController
@RefreshScope @RefreshScope
......
...@@ -2,6 +2,8 @@ package com.dituhui.pea.user.controller; ...@@ -2,6 +2,8 @@ package com.dituhui.pea.user.controller;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.enums.RedisKeyGroup; import com.dituhui.pea.enums.RedisKeyGroup;
import com.dituhui.pea.enums.StatusCodeEnum; import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.enums.ThirdPartyEnum; import com.dituhui.pea.enums.ThirdPartyEnum;
...@@ -13,13 +15,15 @@ import org.apache.commons.lang.StringUtils; ...@@ -13,13 +15,15 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
* 用户控制层 * 用户控制层
* *
* @author zl
* @since 2020-12-09 15:42:00
*/ */
@RestController @RestController
public class UserController implements IUser { public class UserController implements IUser {
...@@ -29,6 +33,14 @@ public class UserController implements IUser { ...@@ -29,6 +33,14 @@ public class UserController implements IUser {
@Autowired @Autowired
private RedisService redisService; private RedisService redisService;
public Result<?> userLogin(UserLoginDTO user) {
return userService.userLogin(user.getAccount(), user.getAccount());
}
public Result<?> getUserInfo(String token) {
return userService.getUserInfo(token);
}
@Override @Override
public WebResult<UserInfo> getCurrentUserInfo(String userToken, Boolean needTeamInfo) { public WebResult<UserInfo> getCurrentUserInfo(String userToken, Boolean needTeamInfo) {
......
package com.dituhui.pea.user.dao; package com.dituhui.pea.user.dao;
import java.util.List; import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
...@@ -15,56 +14,72 @@ import com.dituhui.pea.user.entity.UserEntity; ...@@ -15,56 +14,72 @@ import com.dituhui.pea.user.entity.UserEntity;
* @author zl * @author zl
* @since 2020-12-09 15:34:42 * @since 2020-12-09 15:34:42
*/ */
public interface UserDao extends JpaRepository<UserEntity, String>, public interface UserDao extends JpaRepository<UserEntity, String>, JpaSpecificationExecutor<UserEntity>,
JpaSpecificationExecutor<UserEntity>, CrudRepository<UserEntity, String> { CrudRepository<UserEntity, String> {
/**
* 根据手机号查询
*
* @param phoneNumber 手机号码
* @return
*/
UserEntity findByPhone(String phone);
/** /**
* 根据手机号查询 * 根据邮箱查询
* @param phoneNumber 手机号码 *
* @return * @param email 邮箱
*/ * @return
UserEntity findByPhone(String phone); */
UserEntity findByEmail(String email);
/** /**
* 根据邮箱查询 * 根据微信查询
* @param email 邮箱 *
* @return * @param wechat 微信
*/ * @return
UserEntity findByEmail(String email); */
List<UserEntity> findByWechat(String wechat);
/** /**
* 根据微信查询 * 根据微信小程序查询
* @param wechat 微信 *
* @return * @param wechatMiniProgram 微信小程序openId
*/ * @return
List<UserEntity> findByWechat(String wechat); */
List<UserEntity> findByWechatMiniProgram(String wechatMiniProgram);
/** /**
* 根据微信小程序查询 * 根据账号查询
* @param wechatMiniProgram 微信小程序openId *
* @return * @param account 账号
*/ * @return
List<UserEntity> findByWechatMiniProgram(String wechatMiniProgram); */
UserEntity findByAccount(String account);
/** /**
* 根据账号查询 * 根据账号查询
* @param account 账号 *
* @return * @param account 账号
*/ * @param password 加密密码
UserEntity findByAccount(String account); * @return
*/
UserEntity findByAccountAndPassword(String account, String password);
/** /**
* 根据账号查询 * 根据账号查询
* @param account 账号 *
* @return * @param account 账号
*/ * @return
List<UserEntity> findAllByAccount(String account); */
List<UserEntity> findAllByAccount(String account);
/** /**
* 根据用户ID批量查询 * 根据用户ID批量查询
* @param userIds 用户ID集合 *
* @return * @param userIds 用户ID集合
*/ * @return
List<UserEntity> findByIdIn(List<String> userIds); */
List<UserEntity> findByIdIn(List<String> userIds);
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!