乘客api调用用户服务,无用户则注册用户

master
liuyuanqiang 2 years ago
parent ade98fafb5
commit 7c7dd6707a

@ -37,7 +37,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.mashibing</groupId>
<artifactId>internal-common</artifactId>
</dependency>
</dependencies>

@ -0,0 +1,15 @@
package com.mashibing.apipassenger.remote;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.request.VerificationCodeDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@FeignClient("service-passenger-user")
public interface ServicePassengerUserClient {
@PostMapping("/user")
public ResponseResult loginOrRegister(@RequestBody VerificationCodeDTO verificationCodeDTO);
}

@ -1,8 +1,10 @@
package com.mashibing.apipassenger.service;
import com.mashibing.apipassenger.remote.ServicePassengerUserClient;
import com.mashibing.apipassenger.remote.ServiceVefificationcodeClient;
import com.mashibing.common.constant.CommonStatusEnum;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.request.VerificationCodeDTO;
import com.mashibing.common.response.NumberCodeResponse;
import com.mashibing.common.response.TokenResponse;
import net.sf.json.JSONObject;
@ -18,6 +20,8 @@ import java.util.concurrent.TimeUnit;
public class VerificationCodeService {
@Autowired
private ServiceVefificationcodeClient serviceVefificationcodeClient;
@Autowired
private ServicePassengerUserClient servicePassengerUserClient;
@Autowired
private StringRedisTemplate stringRedisTemplate;
@ -69,6 +73,9 @@ public class VerificationCodeService {
return ResponseResult.fail(CommonStatusEnum.VERIFICATION_CODE_FAIL.getCode(),CommonStatusEnum.VERIFICATION_CODE_FAIL.getMsg());
}
System.out.println("判断是否有用户,没有则新增用户");
VerificationCodeDTO verificationCodeDTO = new VerificationCodeDTO();
verificationCodeDTO.setPassengerPhone(passengerPhone);
servicePassengerUserClient.loginOrRegister(verificationCodeDTO);
System.out.println("颁发token");

@ -1,3 +1,5 @@
com\mashibing\common\dto\ResponseResult.class
com\mashibing\common\request\VerificationCodeDTO.class
com\mashibing\common\constant\CommonStatusEnum.class
com\mashibing\common\response\NumberCodeResponse.class
com\mashibing\common\response\TokenResponse.class

@ -1,3 +1,5 @@
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\constant\CommonStatusEnum.java
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\dto\ResponseResult.java
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\response\NumberCodeResponse.java
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\request\VerificationCodeDTO.java
D:\Works\workspaces\online-taxi-public\internal-common\src\main\java\com\mashibing\common\response\TokenResponse.java

@ -42,11 +42,6 @@
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>org.mashibing</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- nacos 依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
@ -73,6 +68,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.mashibing</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>

@ -32,6 +32,14 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mashibing</groupId>
<artifactId>internal-common</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>

@ -6,12 +6,12 @@ import java.time.LocalDateTime;
@Data
public class PassengerUser {
private Long id;
private String passenger_phone;
private String passenger_name;
private byte passenger_gender;
private String passengerPhone;//不是passenger_phone 这里要注意啦!!!
private String passengerName;
private byte passengerGender;
private byte state;
private LocalDateTime gmt_create;
private LocalDateTime gmt_update;
private LocalDateTime gmtCreate;
private LocalDateTime gmtUpdate;
}

@ -1,16 +1,9 @@
package com.mashibing.serviceDriverUser.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mashibing.serviceDriverUser.dto.PassengerUser;
import org.springframework.stereotype.Repository;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@Repository
public interface PassengerUserMapper extends BaseMapper<PassengerUser> {

@ -1,13 +1,12 @@
package com.mashibing.serviceDriverUser.service;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.request.VerificationCodeDTO;
import com.mashibing.serviceDriverUser.dto.PassengerUser;
import com.mashibing.serviceDriverUser.mapper.PassengerUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
@ -15,18 +14,30 @@ import java.util.List;
public class UserService {
@Autowired
private PassengerUserMapper passengerUserMapper;
public ResponseResult loginOrRegister(String passengerPhone){
System.out.println("user service");
//根据手机号查询用户信息
HashMap map = new HashMap();
map.put("passenger_phone",passengerPhone);
List<PassengerUser> user = passengerUserMapper.selectByMap(map);
System.out.println("get db:" + user == null || user.size() == 0?"无记录":user.get(0).getPassenger_name());
//验证信息
List<PassengerUser> user = this.passengerUserMapper.selectByMap(map);
System.out.println(user.size() == 0?"无记录":user.get(0).getPassengerPhone() + user.get(0).getPassengerName());
//若没有用户,插入用户
if(user.size() == 0){
PassengerUser newUser = new PassengerUser();
newUser.setPassengerName("xxoo");
newUser.setPassengerGender((byte)0);
newUser.setPassengerPhone(passengerPhone);
newUser.setState((byte) 0);
LocalDateTime now = LocalDateTime.now();
newUser.setGmtCreate(now);
newUser.setGmtUpdate(now);
this.passengerUserMapper.insert(newUser);
}
return ResponseResult.success();
}

@ -8,6 +8,10 @@ spring:
url: jdbc:mysql://localhost:3306/service-passenger-user?characterEncoding=utf-8&serverTimezone=GMT%2B8
username: root
password: admin
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848

@ -8,6 +8,10 @@ spring:
url: jdbc:mysql://localhost:3306/service-passenger-user?characterEncoding=utf-8&serverTimezone=GMT%2B8
username: root
password: admin
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848

@ -34,6 +34,10 @@
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.mashibing</groupId>
<artifactId>internal-common</artifactId>
</dependency>
</dependencies>
</project>

Loading…
Cancel
Save