service-passenger-user编写根据手机号查询用户信息

main
topsun 2 years ago
parent c7e41b8d31
commit 6c03ff40e8

@ -5,10 +5,11 @@ import com.taxi.apipassenger.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@Service
@RestController
public class UserController {
@Autowired
private UserService userService;

@ -1,5 +1,6 @@
package com.taxi.apipassenger.remote;
import com.internal.dto.PassengerUser;
import com.internal.dto.ResponseResult;
import com.internal.request.VerificationCodeDTO;
import org.springframework.cloud.openfeign.FeignClient;
@ -8,7 +9,10 @@ import org.springframework.web.bind.annotation.*;
@FeignClient("service-passenger-user")
public interface ServicePassengerUserClient {
@RequestMapping(method = RequestMethod.POST,value = " /user")
@RequestMapping(method = RequestMethod.POST,value = "/user")
ResponseResult loginOrReg(@RequestBody VerificationCodeDTO verificationCodeDTO);
@RequestMapping(method = RequestMethod.GET,value = "/userInfo/{passengerPhone}")
ResponseResult<PassengerUser> getUserInfo(@PathVariable("passengerPhone") String passengerPhone);
}

@ -3,22 +3,27 @@ package com.taxi.apipassenger.service;
import com.internal.dto.PassengerUser;
import com.internal.dto.ResponseResult;
import com.internal.dto.TokenResult;
import com.internal.request.VerificationCodeDTO;
import com.internal.util.JwtUtils;
import com.taxi.apipassenger.remote.ServicePassengerUserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
@Autowired
private ServicePassengerUserClient servicePassengerUserClient;
public ResponseResult getUserInfo(String accessToken) {
TokenResult tokenResult = null;
PassengerUser userInfoResult = null;
try {
tokenResult = JwtUtils.checkToken(accessToken);
TokenResult tokenResult = JwtUtils.checkToken(accessToken);
VerificationCodeDTO verificationCodeDTO = new VerificationCodeDTO();
String passengerPhone = tokenResult.getPassengerPhone();
userInfoResult = new PassengerUser();
//根据手机号查询用户信息
userInfoResult = servicePassengerUserClient.getUserInfo(passengerPhone).getData();
} catch (Exception e) {
throw new RuntimeException(e);

@ -4,9 +4,7 @@ import com.internal.dto.ResponseResult;
import com.internal.request.VerificationCodeDTO;
import com.taxi.servicepassengeruser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RestController
public class UserController {
@ -20,4 +18,10 @@ public class UserController {
System.out.println("手机号:" + passengerPhone);
return userService.loginOrReg(passengerPhone);
}
@GetMapping("/userInfo/{passengerPhone}")
public ResponseResult getUserInfo(@PathVariable("passengerPhone") String passengerPhone){
System.out.println("手机号:" + passengerPhone);
return userService.getUserInfo(passengerPhone);
}
}

@ -1,5 +1,6 @@
package com.taxi.servicepassengeruser.service;
import com.internal.contant.CommonStatusEnum;
import com.internal.dto.PassengerUser;
import com.internal.dto.ResponseResult;
import com.taxi.servicepassengeruser.mapper.PassengerUserMapper;
@ -41,4 +42,24 @@ public class UserService {
//如果不存在,插入用户信息
return ResponseResult.success();
}
/**
*
* @param passengerPhone
* @return
*/
public ResponseResult getUserInfo(String passengerPhone){
System.out.println("UserService 被调用, 手机号: " + passengerPhone);
//根据手机号查询用户信息
Map<String,Object> map = new HashMap<>();
map.put("passenger_phone",passengerPhone);
List<PassengerUser> list = passengerUserMapper.selectByMap(map);
System.out.println("查询用户数据条数size= " + list.size());
//判断用户信息是否存在
if(list != null && list.size() > 0){
return ResponseResult.success(list.get(0));
}
return ResponseResult.fail(CommonStatusEnum.FAIL);
}
}

Loading…
Cancel
Save