Compare commits

..

No commits in common. "72ebcefef77b0ff76c1dd4043cf86c7323c1a482" and "916a9868c53f6c7568b71600dbac076a17e94a0b" have entirely different histories.

6 changed files with 21 additions and 111 deletions

View File

@ -7,7 +7,6 @@ import com.example.caseData.dto.publicDto.LoginDto;
import com.example.caseData.dto.user.UserDto;
import com.example.caseData.extend.aliyun.Oss;
import com.example.caseData.request.publicRequest.GetOssSignRequest;
import com.example.caseData.request.publicRequest.LoginHcpRequest;
import com.example.caseData.request.publicRequest.LoginRequest;
import com.example.caseData.request.UserRequest.UserRequest;
import com.example.caseData.service.UserService;
@ -32,7 +31,7 @@ public class PublicController {
// 登陆
@PostMapping("/login/wechat/mobile")
public Response<LoginDto> loginWechatMobile(@Validated({LoginRequest.Login.class}) @ModelAttribute LoginRequest request) {
public Response<LoginDto> login(@Validated({LoginRequest.Login.class}) @ModelAttribute LoginRequest request) {
// 微信手机号授权登录
// 获取手机号
// 获取用户openid
@ -41,19 +40,11 @@ public class PublicController {
String phone = "18221234167";
// 用户登陆
LoginDto g = userService.UserLoginWithMobile(phone);
LoginDto g = userService.UserLogin(phone);
return Response.success(g);
}
// 登陆
@PostMapping("/login/hcp")
public Response<LoginDto> loginHcp(@Validated() @ModelAttribute LoginHcpRequest request) {
// 用户登陆
LoginDto g = userService.UserLoginWithApp(request.getToken());
return Response.success(g);
}
// 获取签名
@GetMapping("/sign/oss")
public Response<GetOssSignDto> GetOssSign(

View File

@ -1,5 +1,6 @@
package com.example.caseData.extend.app.Hospital;
import com.example.caseData.extend.app.UserInfo.GetUserInfoByMobileResponse;
import lombok.Data;
@Data

View File

@ -3,7 +3,7 @@ package com.example.caseData.extend.app.UserInfo;
import lombok.Data;
@Data
public class GetUserInfoResponse {
public class GetUserInfoByMobileResponse {
/** 接口调用状态。200正常其它值调用出错 */
private int code;
@ -11,7 +11,7 @@ public class GetUserInfoResponse {
private String msg;
/** 接口返回的用户信息数据 */
private ResponsData data;
private GetUserInfoByMobileData data;
/** 接口是否调用成功 */
private boolean success;
@ -20,8 +20,11 @@ public class GetUserInfoResponse {
private String message;
/**
* 根据手机号获取医生信息 - 详细数据
*/
@Data
public static class ResponsData {
public static class GetUserInfoByMobileData {
/** app唯一标识 */
private String uuid;

View File

@ -21,7 +21,7 @@ public class UserInfo extends Base {
private AppConfig appConfig;
// 根据手机号获取信息V3
public GetUserInfoResponse getUserInfoByMobile(String mobile) throws BusinessException {
public GetUserInfoByMobileResponse getUserInfoByMobile(String mobile) throws BusinessException {
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
// 处理参数
@ -48,53 +48,7 @@ public class UserInfo extends Base {
}
// 反序列化 JSON
GetUserInfoResponse result = JSONUtil.toBean(response.body(), GetUserInfoResponse.class);
log.info("获取app数据返回:{}",result);
if (result.getCode() != 200){
if (!Objects.equals(result.getMsg(), "")){
throw new BusinessException(result.getMsg());
}else{
throw new BusinessException("失败");
}
}
if (result.getData() == null){
throw new BusinessException("失败");
}
return result;
}
}
// 根据token获取信息V3
public GetUserInfoResponse getUserInfoByToken(String appToken) throws BusinessException {
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
// 处理参数
Map<String, Object> requestData = new HashMap<>();
requestData.put("token", appToken);
requestData.put("platform", appConfig.getPlatform());
requestData.put("timestamp", timestamp);
// 生成签名
String sign = genSignature(requestData,appConfig.getSecretKey());
String url = appConfig.getApiUrl() + "/expert-api/getInfoByToken";
String jsonBody = JSONUtil.toJsonStr(requestData);
log.info("获取app数据参数:{}",jsonBody);
try(HttpResponse response = HttpRequest.post(url)
.header("Content-Type", "application/json")
.header("sign", sign)
.body(jsonBody)
.execute()){
if (response.getStatus() != 200) {
throw new BusinessException("失败");
}
// 反序列化 JSON
GetUserInfoResponse result = JSONUtil.toBean(response.body(), GetUserInfoResponse.class);
GetUserInfoByMobileResponse result = JSONUtil.toBean(response.body(), GetUserInfoByMobileResponse.class);
log.info("获取app数据返回:{}",result);
if (result.getCode() != 200){
if (!Objects.equals(result.getMsg(), "")){

View File

@ -1,10 +0,0 @@
package com.example.caseData.request.publicRequest;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
@Data
public class LoginHcpRequest {
@NotEmpty(message = "错误请求")
private String token;
}

View File

@ -9,7 +9,7 @@ import com.example.caseData.dto.publicDto.LoginDto;
import com.example.caseData.exception.BusinessException;
import com.example.caseData.extend.app.Hospital.GetHospitalByUuidResponse;
import com.example.caseData.extend.app.Hospital.Hospital;
import com.example.caseData.extend.app.UserInfo.GetUserInfoResponse;
import com.example.caseData.extend.app.UserInfo.GetUserInfoByMobileResponse;
import com.example.caseData.extend.app.UserInfo.UserInfo;
import com.example.caseData.model.BasicHospitalModel;
import com.example.caseData.model.CaseClinicalDoctorModel;
@ -46,14 +46,13 @@ public class UserService {
private JwtUtil jwtUtil;
/**
* 用户登陆-手机号
* 用户登陆
* @return UserModel
*/
@Transactional
public LoginDto UserLoginWithMobile(String phone) throws BusinessException {
public LoginDto UserLogin(String phone) throws BusinessException {
// 获取app用户数据
GetUserInfoResponse result = userInfo.getUserInfoByMobile(phone);
UserModel user = GetAppUserInfo(result);
UserModel user = GetAppUserInfoByPhone(phone);
// 生成jwt
String token = jwtUtil.createToken(String.valueOf(user.getUserId()));
@ -76,47 +75,19 @@ public class UserService {
return g;
}
/**
* 用户登陆-app
* @param appToken 1
*/
@Transactional
public LoginDto UserLoginWithApp(String appToken) throws BusinessException {
GetUserInfoResponse result = userInfo.getUserInfoByToken(appToken);
UserModel user = GetAppUserInfo(result);
// 生成jwt
String token = jwtUtil.createToken(String.valueOf(user.getUserId()));
// 获取对应医生数据
LambdaQueryWrapper<CaseClinicalDoctorModel> caseClinicalDoctorWrapper = new LambdaQueryWrapper<>();
caseClinicalDoctorWrapper.eq(CaseClinicalDoctorModel::getDoctorIden, user.getUserIden());
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectOne(caseClinicalDoctorWrapper);
// 处理返回值
LoginDto g = new LoginDto();
g.setUserId(String.valueOf(user.getUserId()));
g.setUserName(user.getUserName());
g.setAvatar(Replace.addOssDomain(user.getAvatar()));
g.setToken(token);
if (caseClinicalDoctor != null) {
g.setDoctorId(String.valueOf(caseClinicalDoctor.getDoctorId()));
}
return g;
}
/**
* 获取app用户数据
* @param phone 手机号
* @return UserModel
*/
public UserModel GetAppUserInfo(GetUserInfoResponse r) throws BusinessException {
GetUserInfoResponse.ResponsData data = r.getData();
public UserModel GetAppUserInfoByPhone(String phone) throws BusinessException {
// 请求接口获取数据
GetUserInfoByMobileResponse result = userInfo.getUserInfoByMobile(phone);
GetUserInfoByMobileResponse.GetUserInfoByMobileData data = result.getData();
// 查询数据库用户信息
LambdaQueryWrapper<UserModel> userModelWrapper = new LambdaQueryWrapper<>();
userModelWrapper.eq(UserModel::getUserIden, r.getData().getUuid());
userModelWrapper.eq(UserModel::getUserIden, result.getData().getUuid());
UserModel user = userDao.selectOne(userModelWrapper);
if (user == null){
// 构造 UserModel 对象