dev
hgx 1 year ago
parent fb0d4915a9
commit 8c2a321164

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api-passenger</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- add nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,15 @@
package com.mashibing.apipassenger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ApiPassengerApplication {
public static void main(String[] args) {
SpringApplication.run(ApiPassengerApplication.class);
}
}

@ -0,0 +1,113 @@
package com.mashibing.apipassenger.Service;
import com.mashibing.apipassenger.remote.ServicePassengerUserClient;
import com.mashibing.apipassenger.remote.ServiceVerificationCodeClient;
import com.mashibing.internal.common.constant.CommonStatusEnum;
import com.mashibing.internal.common.dto.ResponseResult;
import com.mashibing.internal.common.request.VerificationCodeDTO;
import com.mashibing.internal.common.response.NumberCodeResponse;
import com.mashibing.internal.common.response.TokenResponse;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
@Service
public class VerificationCodeService {
@Autowired
private
ServiceVerificationCodeClient serviceVerificationCodeClient;
//乘客验证码的前缀
private String verificationCodePrefix = "passenger-verification-code-";
@Autowired
private StringRedisTemplate stringRedisTemplate;
/**
*
* @param passengerPhone
* @return
*/
public ResponseResult generatorCode(String passengerPhone) {
// 调用验证码服务,获取验证码
System.out.println("调用验证码服务,获取验证码");
ResponseResult<NumberCodeResponse> numberCodeResponse = serviceVerificationCodeClient.getNumberCode(6);
int numberCode = numberCodeResponse.getData().getNumberCode();
System.out.println("remote numberCode "+numberCode);
String code ="101111";
//存入redis
System.out.println("存入redis");
//key,value,过期时间
String key = generatorKeyByPhone(passengerPhone);
stringRedisTemplate.opsForValue().set(key,numberCode+"",2, TimeUnit.MINUTES);
// 通过短信服务商,将对应的验证码发送到手机上,阿里短信服务,腾讯短信通,华信,容联
return ResponseResult.success();
}
/**
* key
* @param passengerPhone
* @return
*/
private String generatorKeyByPhone(String passengerPhone){
return verificationCodePrefix+passengerPhone;
}
@Autowired
private ServicePassengerUserClient servicePassengerUserClient;
/**
*
* @param passengerPhone
* @param verificationCode
* @return
*/
public ResponseResult checkCode(String passengerPhone,String verificationCode){
// 根据手机号去redis读取验证码
System.out.println("根据手机号去redis读取验证码");
//生成key
String key = generatorKeyByPhone(passengerPhone);
//根据key获取value
String codeRedis = stringRedisTemplate.opsForValue().get(key);
System.out.println("redis中的value:" + codeRedis);
// 校验验证码
System.out.println("校验验证码");
if(StringUtils.isBlank(codeRedis)){
return ResponseResult.fail(CommonStatusEnum.VERIFICATION_CODE_ERROR.getCode(),CommonStatusEnum.VERIFICATION_CODE_ERROR.getValue());
}
if(!verificationCode.trim().equals(codeRedis.trim())){
return ResponseResult.fail(CommonStatusEnum.VERIFICATION_CODE_ERROR.getCode(),CommonStatusEnum.VERIFICATION_CODE_ERROR.getValue());
}
// 判断原来是否有用户,并进行对应得处理
VerificationCodeDTO verificationCodeDTO=new VerificationCodeDTO();
verificationCodeDTO.setPassengerPhone(passengerPhone);
servicePassengerUserClient.loginOrRegister(verificationCodeDTO);
// 颁发令牌
System.out.println("颁发令牌");
//响应
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setToken("token value");
return ResponseResult.success(tokenResponse);
}
}

@ -0,0 +1,12 @@
package com.mashibing.apipassenger.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@GetMapping("/test")
public String test(){
return "test api passenger";
}
}

@ -0,0 +1,34 @@
package com.mashibing.apipassenger.controller;
import com.mashibing.apipassenger.Service.VerificationCodeService;
import com.mashibing.internal.common.request.VerificationCodeDTO;
import com.mashibing.internal.common.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
@RestController
public class VerificationCodeController {
@Autowired
private VerificationCodeService verificationCodeService;
@GetMapping("/verification-code")
private ResponseResult verificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO ){
String passengerPhone = verificationCodeDTO.getPassengerPhone();
System.out.println(passengerPhone);
return verificationCodeService.generatorCode(passengerPhone);
}
@PostMapping("/verification-code-check")
public ResponseResult checkVerificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
String passengerPhone = verificationCodeDTO.getPassengerPhone();
System.out.println(passengerPhone);
String verificationCode = verificationCodeDTO.getVerificationCode();
System.out.println("手机号"+ passengerPhone + ",验证码:"+verificationCode);
return verificationCodeService.checkCode(passengerPhone,verificationCode);
}
}

@ -0,0 +1,88 @@
package com.mashibing.apipassenger.mashibing.ch01;
public class MyArray {
private long[] arr;
//表示有效数据的长度
private int elements;
public MyArray(){
arr =new long[50];
}
public MyArray(int maxSize){
arr = new long[maxSize];
}
/**
*
*/
public void insert(long value){
arr[elements] =value;
elements++;
}
/**
*
*/
public void display(){
System.out.print("[");
for(int i=0;i<elements;i++){
System.out.print(arr[i]+" ");
}
System.out.println("]");
}
/**
*
*/
public int search(long value){
int i;
for(i=0;i<elements;i++){
if(value == arr[i]){
break;
}
}
if(i == elements){
return -1;
}else{
return i;
}
}
/**
*
*/
public long get(int index){
if(index>=elements || index<0){
throw new ArrayIndexOutOfBoundsException();
}else{
return arr[index];
}
}
/**
*
*/
public void delete(int index){
if(index>=elements || index < 0){
throw new ArrayIndexOutOfBoundsException();
}else{
for(int i =index;i<elements;i++){
arr[index] = arr[index+1];
}
elements--;
}
}
/**
*
*/
public void change(int index,int newValue){
if(index>=elements || index < 0){
throw new ArrayIndexOutOfBoundsException();
}else {
arr[index] =newValue;
}
}
}

@ -0,0 +1,121 @@
package com.mashibing.apipassenger.mashibing.ch01;
public class MyOrderArray {
private long[] arr;
//表示有效数据的长度
private int elements;
public MyOrderArray(){
arr =new long[50];
}
public MyOrderArray(int maxSize){
arr = new long[maxSize];
}
/**
*
*/
public void insert(long value){
int i;
for(i=0;i<elements;i++){
if(arr[i]>value){
break;
}
}
for(int j=elements;j>i;j--){
arr[j] =arr[j-1];
}
arr[i] = value;
elements++;
}
/**
*
*/
public void display(){
System.out.print("[");
for(int i=0;i<elements;i++){
System.out.print(arr[i]+" ");
}
System.out.println("]");
}
/**
*
*/
public int search(long value){
int i;
for(i=0;i<elements;i++){
if(value == arr[i]){
break;
}
}
if(i == elements){
return -1;
}else{
return i;
}
}
/**
*
*/
public int binarySearch(long value){
int middle =0;
int low = 0;
int pow = elements;
while(true){
middle = (pow+low) / 2;
if(arr[middle] == value){
return middle;
}else if(low>pow){
return -1;
}else{
if(arr[middle] > value) {
pow =middle -1;
}else{
low = middle +1;
}
}
}
}
/**
*
*/
public long get(int index){
if(index>=elements || index<0){
throw new ArrayIndexOutOfBoundsException();
}else{
return arr[index];
}
}
/**
*
*/
public void delete(int index){
if(index>=elements || index < 0){
throw new ArrayIndexOutOfBoundsException();
}else{
for(int i =index;i<elements;i++){
arr[index] = arr[index+1];
}
elements--;
}
}
/**
*
*/
public void change(int index,int newValue){
if(index>=elements || index < 0){
throw new ArrayIndexOutOfBoundsException();
}else {
arr[index] =newValue;
}
}
}

@ -0,0 +1,16 @@
package com.mashibing.apipassenger.mashibing.ch01;
public class TestArray {
public static void main(String[] args){
long[] arr = new long[]{
2,3,4
};
arr[0] =1;
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
}
}

@ -0,0 +1,19 @@
package com.mashibing.apipassenger.mashibing.ch01;
public class TestMyArray {
public static void main(String[] args) {
MyArray arr = new MyArray();
arr.insert(13);
arr.insert(34);
arr.insert(90);
arr.display();
System.out.println(arr.search(34));
System.out.println(arr.get(1));
arr.delete(1);
arr.display();
arr.change(0,12);
arr.display();
}
}

@ -0,0 +1,16 @@
package com.mashibing.apipassenger.mashibing.ch01;
public class TestMyOrderArray {
public static void main(String[] args) {
MyOrderArray arr = new MyOrderArray();
arr.insert(13);
arr.insert(34);
arr.insert(90);
arr.insert(10);
arr.display();
System.out.println(arr.binarySearch(90));
}
}

@ -0,0 +1,18 @@
package com.mashibing.apipassenger.mashibing.ch02;
public class BubbleSort {
public static void sort(long[] arr){
long temp =0;
for(int i =0;i<arr.length -1;i++){
for(int j=arr.length-1;j>i;j--){
if(arr[j]<arr[j-1]){
//进行交换
temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] =temp;
}
}
}
}
}

@ -0,0 +1,17 @@
package com.mashibing.apipassenger.mashibing.ch02;
public class InsertSort {
public static void sort(long[] arr){
long temp =0;
for(int i=1;i<arr.length;i++){
temp =arr[i];
int j=i;
while(j>0 && arr[j]>=temp){
arr[j] =arr[j-1];
j--;
}
arr[j] =temp;
}
}
}

@ -0,0 +1,20 @@
package com.mashibing.apipassenger.mashibing.ch02;
public class SelectionSort {
public static void sort(long[] arr){
int k=0;
long temp =0;
for(int i=0;i<arr.length-1;i++){
k=i;
for(int j=i;j<arr.length;j++){
if(arr[j] <arr[k]){
k=j;
}
}
temp =arr[i];
arr[i] = arr[k];
arr[k] = temp;
}
}
}

@ -0,0 +1,26 @@
package com.mashibing.apipassenger.mashibing.ch02;
public class TestSelectionSort {
public static void main(String[] args){
long[] arr = new long[5];
arr[0] =34;
arr[1] =23;
arr[2] =2;
arr[3] =1;
arr[4] =-4;
System.out.print("[");
for(long num:arr){
System.out.print(num+" ");
}
System.out.print("]");
System.out.println();
InsertSort.sort(arr);
System.out.print("[");
for(long num:arr){
System.out.print(num+" ");
}
System.out.print("]");
System.out.println();
}
}

@ -0,0 +1,26 @@
package com.mashibing.apipassenger.mashibing.ch02;
public class TestSort {
public static void main(String[] args){
long[] arr = new long[5];
arr[0] =34;
arr[1] =23;
arr[2] =2;
arr[3] =1;
arr[4] =-4;
System.out.print("[");
for(long num:arr){
System.out.print(num+" ");
}
System.out.print("]");
System.out.println();
BubbleSort.sort(arr);
System.out.print("[");
for(long num:arr){
System.out.print(num+" ");
}
System.out.print("]");
System.out.println();
}
}

@ -0,0 +1,74 @@
package com.mashibing.apipassenger.mashibing.ch03;
/**
*
*/
public class MyCycleQueue {
//底层使用数组
private long[] arr;
//有效数据大小
private int elements;
//队头
private int front;
//队尾
private int end;
/**
*
*/
public MyCycleQueue(){
arr = new long[10];
elements = 0;
front =0;
end =-1;
}
/**
*
*/
public MyCycleQueue(int maxSize){
arr = new long[maxSize];
elements =0;
front =0;
end = -1;
}
/**
* ,
*/
public void insert(long value){
if(end == arr.length -1){
end = -1;
}
arr[++end] = value;
elements++;
}
/**
*
*/
public long remove(){
long value = arr[front++];
if(front == arr.length){
front = 0;
}
elements--;
return value;
}
/**
*
*/
public long peek(){
return arr[front];
}
/**
*
*/
public boolean isEmpty(){
return elements == 0;
}
/**
*
*/
public boolean isFull(){
return elements == arr.length;
}
}

@ -0,0 +1,67 @@
package com.mashibing.apipassenger.mashibing.ch03;
/**
*
*/
public class MyQueue {
//底层使用数组
private long[] arr;
//有效数据大小
private int elements;
//队头
private int front;
//队尾
private int end;
/**
*
*/
public MyQueue(){
arr = new long[10];
elements = 0;
front =0;
end =-1;
}
/**
*
*/
public MyQueue(int maxSize){
arr = new long[maxSize];
elements =0;
front =0;
end = -1;
}
/**
* ,
*/
public void insert(long value){
arr[++end] = value;
elements++;
}
/**
*
*/
public long remove(){
elements--;
return arr[front++];
}
/**
*
*/
public long peek(){
return arr[front];
}
/**
*
*/
public boolean isEmpty(){
return elements == 0;
}
/**
*
*/
public boolean isFull(){
return elements == arr.length;
}
}

@ -0,0 +1,61 @@
package com.mashibing.apipassenger.mashibing.ch03;
public class MyStack {
//底层实现是一个数组
private long[] arr;
private int top;
/**
*
*/
public MyStack(){
arr =new long[10];
top =-1;
}
/**
*
*/
public MyStack(int maxSize){
arr = new long[maxSize];
top =-1;
}
/**
*
*/
public void push(int value){
arr[++top]= value;
}
/**
*
*/
public long pop(){
return arr[top--];
}
/**
*
*/
public long peek(){
return arr[top];
}
/**
*
*/
public boolean isEmpty(){
return top ==-1;
}
/**
*
*/
public boolean isFull(){
return top == arr.length -1;
}
}

@ -0,0 +1,26 @@
package com.mashibing.apipassenger.mashibing.ch03;
public class TestMyCycleQueue {
public static void main(String[] args){
MyCycleQueue mq= new MyCycleQueue(4);
mq.insert(23);
mq.insert(45);
mq.insert(13);
mq.insert(1);
System.out.println(mq.isFull());
System.out.println(mq.isEmpty());
System.out.println(mq.peek());
while(!mq.isEmpty()){
System.out.println(mq.remove()+" ");
}
mq.insert(23);
mq.insert(45);
mq.insert(13);
mq.insert(1);
while(!mq.isEmpty()){
System.out.println(mq.remove()+" ");
}
}
}

@ -0,0 +1,20 @@
package com.mashibing.apipassenger.mashibing.ch03;
public class TestMyQueue {
public static void main(String[] args){
MyQueue mq= new MyQueue(4);
mq.insert(23);
mq.insert(45);
mq.insert(13);
mq.insert(1);
System.out.println(mq.isFull());
System.out.println(mq.isEmpty());
System.out.println(mq.peek());
while(!mq.isEmpty()){
System.out.println(mq.remove()+" ");
}
mq.insert(23);
}
}

@ -0,0 +1,24 @@
package com.mashibing.apipassenger.mashibing.ch03;
public class TestMyStack {
public static void main(String[] args) {
MyStack myStack = new MyStack(4);
myStack.push(23);
myStack.push(12);
myStack.push(1);
myStack.push(90);
System.out.println(myStack.isEmpty());
System.out.println(myStack.isFull());
System.out.println(myStack.peek());
System.out.println(myStack.peek());
while(!myStack.isEmpty()){
System.out.println(myStack.pop() + ",");
}
System.out.println(myStack.isEmpty());
System.out.println(myStack.isFull());
}
}

@ -0,0 +1,77 @@
package com.mashibing.apipassenger.mashibing.ch04;
/**
*
*/
public class LinkList {
//头节点
private Node first;
public LinkList(){
first = null;
}
/**
*
*/
public void insertFirst(long value){
Node node = new Node(value);
node.next = first;
first = node;
}
/**
*
*/
public Node deleteFirst(){
Node tmp = first;
first = tmp.next;
return tmp;
}
/**
*
*/
public void display(){
Node current = first;
while(current != null){
current.display();
current = current.next;
}
System.out.println();
}
/**
*
*/
public Node find(long value){
Node current = first;
while(current.data != value){
if(current.next == null){
return null;
}
current = current.next;
}
return current;
}
/**
*
*/
public Node delete(long value){
Node current = first;
Node previous = first;
while(current.data != value){
if(current.next == null){
return null;
}
previous = current;
current = current.next;
}
if(current == first){
first = first.next;
}else{
previous.next= current.next;
}
return current;
}
}

@ -0,0 +1,26 @@
package com.mashibing.apipassenger.mashibing.ch04;
/**
*
*/
public class Node {
//数据域
public long data;
//结点域指针域下一个节点的引用
public Node next;
public Node(long value){
this.data = value;
}
/**
*
*/
public void display(){
System.out.print(data + " ");
}
}

@ -0,0 +1,15 @@
package com.mashibing.apipassenger.mashibing.ch04;
public class TestLinkList {
public static void main(String[] args){
LinkList linkList = new LinkList();
linkList.insertFirst(12);
linkList.insertFirst(23);
linkList.insertFirst(34);
linkList.display();
linkList.deleteFirst();
linkList.display();
linkList.delete(12);
linkList.display();
}
}

@ -0,0 +1,14 @@
package com.mashibing.apipassenger.mashibing.ch06;
public class Fibonacci {
public static int getNumber(int n){
if(n==1){
return 0;
}else if(n ==2){
return 1;
}else{
return getNumber(n-1)+getNumber(n-2);
}
}
}

@ -0,0 +1,21 @@
package com.mashibing.apipassenger.mashibing.ch06;
public class Recursion {
public static void main(String[] args){
test2(100);
}
public static void test(){
System.out.println("Hello world!");
test();
}
public static void test2(int n){
System.out.println(n);
if(n == 0){
return;
}
test2(n-1);
}
}

@ -0,0 +1,8 @@
package com.mashibing.apipassenger.mashibing.ch06;
public class TestFibonacci {
public static void main(String[] args){
System.out.println(Fibonacci.getNumber(20));
}
}

@ -0,0 +1,8 @@
package com.mashibing.apipassenger.mashibing.ch06;
public class TestTriangle {
public static void main(String[] args) {
System.out.println(Triangle.getNumber(500));
System.out.println(Triangle.getNumberByRecursion(500));
}
}

@ -0,0 +1,22 @@
package com.mashibing.apipassenger.mashibing.ch06;
public class Triangle {
public static int getNumber(int n){
int total =0;
while(n>0){
total=total+n;
n--;
}
return total;
}
public static int getNumberByRecursion(int n){
if(n == 1){
return 1;
}else{
return n+getNumberByRecursion(n-1);
}
}
}

@ -0,0 +1,21 @@
package com.mashibing.apipassenger.mashibing.ch07;
public class HanoiTower {
/**
*
* topN:
* from:
* inter:
* to:
*/
public static void doTower(int topN,char from,char inter,char to){
if(topN ==1){
System.out.println("盘子1,从" +from+"塔座到"+to+"塔座");
}else{
doTower(topN-1,from,to,inter);
System.out.println("盘子"+topN +",从"+from +"塔座到"+to +"塔座");
doTower(topN-1,inter,from,to);
}
}
}

@ -0,0 +1,7 @@
package com.mashibing.apipassenger.mashibing.ch07;
public class TestHanoiTower {
public static void main(String[] args){
HanoiTower.doTower(3,'A','B','C');
}
}

@ -0,0 +1,31 @@
package com.mashibing.apipassenger.mashibing.ch08;
public class ShellSort {
/**
*
*/
public static void sort(long[] arr){
//初始化一个间隔
int h=1;
//计算最大间隔
while(h<arr.length / 3){
h = h *3+1;
}
while(h>0){
//进行插入排序
long temp =0;
for(int i=h;i<arr.length;i++){
temp =arr[i];
int j =i;
while(j>h-1 && arr[j-h] >= temp){
arr[j]=arr[j-h];
j-=h;
}
arr[j] = temp;
}
//减小间隔
h= (h-1)/3;
}
}
}

@ -0,0 +1,28 @@
package com.mashibing.apipassenger.mashibing.ch08;
import com.mashibing.apipassenger.mashibing.ch02.BubbleSort;
public class TestShellSort {
public static void main(String[] args){
long[] arr = new long[5];
arr[0] =34;
arr[1] =23;
arr[2] =2;
arr[3] =1;
arr[4] =-4;
System.out.print("[");
for(long num:arr){
System.out.print(num+" ");
}
System.out.print("]");
System.out.println();
ShellSort.sort(arr);
System.out.print("[");
for(long num:arr){
System.out.print(num+" ");
}
System.out.print("]");
System.out.println();
}
}

@ -0,0 +1,26 @@
package com.mashibing.apipassenger.mashibing.ch09;
public class QuickSort {
/**
*
*/
public static void partition(long arr[] ,int left,int right,int point){
int leftPtr = left-1;
int rightPtr = right + 1;
while(true){
//循环,将比关键字小的留在左端
while(leftPtr<rightPtr && arr[++leftPtr]<point);
//循环,将比关键字大的留在右端
while(rightPtr>leftPtr && arr[--rightPtr] >point) ;
if(leftPtr>=rightPtr){
return;
}else{
long temp = arr[leftPtr];
arr[leftPtr] = arr[rightPtr];
arr[rightPtr] =temp;
}
}
}
}

@ -0,0 +1,27 @@
package com.mashibing.apipassenger.mashibing.ch09;
public class TestQuickSort {
public static void main(String[] args){
long[] arr =new long[10];
for(int i=0;i<10;i++){
arr[i] = (long)(Math.random()*99);
}
System.out.print("[");
for(long num:arr){
System.out.print(num+" ");
}
System.out.print("]");
System.out.println();
QuickSort.partition(arr,0,arr.length-1,45);
System.out.print("[");
for(long num:arr){
System.out.print(num+" ");
}
System.out.print("]");
System.out.println();
}
}

@ -0,0 +1,25 @@
package com.mashibing.apipassenger.mashibing.ch10;
import lombok.Data;
@Data
public class Node {
//数据项
public long data;
//数据项
public String sData;
//左子节点
public Node leftChild;
//右子节点
public Node rightChild;
public Node(long data) {
this.data = data;
}
public Node(long data,String sData){
this.data = data;
this.sData=sData;
}
}

@ -0,0 +1,67 @@
package com.mashibing.apipassenger.mashibing.ch10;
/**
*
*/
public class Tree {
//根节点
public Node root;
/**
*
* @param value
*/
public void insert(long value){
//封装节点
Node newNode = new Node(value);
//引用当前节点
Node current = root;
//易怒用父节点
Node parent;
//如果root为努力了也就是第一插入的时候
if(root == null){
root = newNode;
return;
}else{
while(true) {
//父节点指向当前
parent = current;
if (current.data > value) {
current = current.leftChild;
if(current == null){
parent.leftChild = newNode;
return;
}
} else {
current = current.rightChild;
if(current == null){
parent.rightChild = newNode;
return;
}
}
}
}
}
/**
*
* @param value
*/
public Node find(long value){
//引用当前节点,从根节点开始
Node current = root;
//循环,只要查找值不等于当前节点的数据项
while(current.data != value){
//进行比较,比较查找值和当前节点的大小
if(current.data >value){
current = current.leftChild;
}else{
current = current.rightChild;
}
if(current == null){
return null;
}
}
return current;
}
}

@ -0,0 +1,26 @@
package com.mashibing.apipassenger.mashibing.ch18;
/**
*
*/
public class Graph {
//顶点数组
private Vertex[] vertexList;
//邻接矩阵
private int[][] adjMat;
//顶点的最大数目
private int maxSize;
//当前顶点
private int nVertex;
public Graph(){
vertexList = new Vertex[maxSize];
adjMat = new int[maxSize][maxSize];
for(int i=0;i<maxSize;i++){
for(int j =0;j<maxSize;j++){
adjMat[i][j] =0;
}
}
nVertex =0;
}
}

@ -0,0 +1,13 @@
package com.mashibing.apipassenger.mashibing.ch18;
/**
*
*/
public class Vertex {
private char label;
public Vertex(char label){
this.label = label;
}
}

@ -0,0 +1,32 @@
package com.mashibing.apipassenger.mashibing.ch21;
public class BubbleSort {
public static void main(String[] args){
int[] a = {9,3,1,4,6,8,7,5,2};
sort(a);
print(a);
}
static void sort(int[] a) {
for(int i=a.length-1;i>0;i--){
for(int j=0;j<i;j++) {
if (a[j] > a[j + 1]) {
swap(a, j, j + 1);
}
}
}
}
static void swap(int[] a,int i,int j){
int temp = a[i];
a[i] = a[j];
a[j] =temp;
}
static void print(int[] arr){
for(int i=0;i<arr.length;i++){
System.out.print(arr[i] + " ");
}
}
}

@ -0,0 +1,31 @@
package com.mashibing.apipassenger.mashibing.ch21;
public class InsertionSort {
public static void main(String[] args){
int[] a = {9,3,1,4,6,8,7,5,2};
sort(a);
print(a);
}
static void sort(int[] a){
for(int i=1;i<a.length;i++){
for(int j=i;j>0;j--){
if(a[j] <a[j-1]){
swap(a,j,j-1);
}
}
}
}
static void swap(int[] a,int i,int j){
int temp =a[i];
a[i]= a[j];
a[j]=temp;
}
static void print(int[] arr){
for(int i=0;i<arr.length;i++){
System.out.print(arr[i] +" ");
}
}
}

@ -0,0 +1,48 @@
package com.mashibing.apipassenger.mashibing.ch21;
public class MergeSort {
public static void main(String[] args){
int[] a = {7,10,15,16,2,5,13};
sort(a);
}
static void sort(int[] a){
merge(a,0,3);
}
static void merge(int[] a,int leftPtr,int mid){
int[] temp =new int[a.length];
int i=leftPtr;
int j=mid +1;
int k=0;
while(i<= mid && j<a.length){
if(a[i]<= a[j]){
temp[k] = a[i];
k++;
i++;
}else{
temp[k] =a[j];
j++;
k++;
}
}
while(i<=mid){
temp[k++]=a[i++];
}
while(j<a.length){
temp[k++] = a[j++];
}
print(temp);
}
static void swap(int[] a,int i,int j){
int temp =a[i];
a[i]= a[j];
a[j]=temp;
}
static void print(int[] arr){
for(int i=0;i<arr.length;i++){
System.out.print(arr[i] +" ");
}
}
}

@ -0,0 +1,16 @@
package com.mashibing.apipassenger.mashibing.ch21;
public class Recursion4 {
public static void main(String[] args) {
System.out.println(f(10));
}
static long f(int n){
if(n<1){
return -1;
}
if(n ==1){
return 1;
}
return n+ f(n-1);
}
}

@ -0,0 +1,37 @@
package com.mashibing.apipassenger.mashibing.ch21;
public class ShellSort {
public static void main(String[] args){
int[] a = {9,6,11,3,5,12,8,7,10,15,14,4,1,13,2};
sort(a);
print(a);
}
static void sort(int[] a){
int h =1;
while(h<a.length/3){
h=h*3 +1;
}
for(int gap =h;gap>0;gap=(gap-1)/3) {
for (int i = gap; i < a.length; i++) {
for (int j = i; j > gap - 1; j -= gap) {
if (a[j] < a[j - gap]) {
swap(a, j, j - gap);
}
}
}
}
}
static void swap(int[] a,int i,int j){
int temp =a[i];
a[i]= a[j];
a[j]=temp;
}
static void print(int[] arr){
for(int i=0;i<arr.length;i++){
System.out.print(arr[i] +" ");
}
}
}

@ -0,0 +1,126 @@
package com.mashibing.apipassenger.mashibing.ch5;
/**
*
*/
public class DoubleLinkList {
//头节点
private Node first;
//尾结点
private Node last;
public DoubleLinkList(){
first = null;
last = null;
}
/**
*
*/
public void insertFirst(long value){
Node node = new Node(value);
if(isEmpty()){
last = node;
}else{
first.previous = node;
}
node.next = first;
first = node;
}
/**
*
*/
public void insertLast(long value){
Node node = new Node(value);
if(isEmpty()){
first = node;
}else{
last.next = node;
node.previous = last;
}
last = node;
}
/**
*
*/
public Node deleteFirst(){
Node tmp = first;
if(first.next == null){
last = null;
}else{
first.next.previous = null;
}
first = tmp.next;
return tmp;
}
/**
*
*/
public Node deleteLast(){
Node tmp = last;
if(first.next == null){
first = null;
}else{
last.previous.next = null;
}
last = last.previous;
return last;
}
/**
*
*/
public void display(){
Node current = first;
while(current != null){
current.display();
current = current.next;
}
System.out.println();
}
/**
*
*/
public Node find(long value){
Node current = first;
while(current.data != value){
if(current.next == null){
return null;
}
current = current.next;
}
return current;
}
/**
*
*/
public Node delete(long value){
Node current = first;
while(current.data != value){
if(current.next == null){
return null;
}
current = current.next;
}
if(current == first){
first = first.next;
}else{
current.previous.next= current.next;
}
return current;
}
/**
*
*/
public boolean isEmpty(){
return first == null;
}
}

@ -0,0 +1,109 @@
package com.mashibing.apipassenger.mashibing.ch5;
import com.mashibing.apipassenger.mashibing.ch04.Node;
/**
*
*/
public class FirstLastLinkList {
//头节点
private Node first;
//尾结点
private Node last;
public FirstLastLinkList(){
first = null;
last = null;
}
/**
*
*/
public void insertFirst(long value){
Node node = new Node(value);
if(isEmpty()){
last = node;
}
node.next = first;
first = node;
}
/**
*
*/
public void insertLast(long value){
Node node = new Node(value);
if(isEmpty()){
first = node;
}else{
last.next = node;
}
last = node;
}
/**
*
*/
public Node deleteFirst(){
Node tmp = first;
if(first.next == null){
last = null;
}
first = tmp.next;
return tmp;
}
/**
*
*/
public void display(){
Node current = first;
while(current != null){
current.display();
current = current.next;
}
System.out.println();
}
/**
*
*/
public Node find(long value){
Node current = first;
while(current.data != value){
if(current.next == null){
return null;
}
current = current.next;
}
return current;
}
/**
*
*/
public Node delete(long value){
Node current = first;
Node previous = first;
while(current.data != value){
if(current.next == null){
return null;
}
previous = current;
current = current.next;
}
if(current == first){
first = first.next;
}else{
previous.next= current.next;
}
return current;
}
/**
*
*/
public boolean isEmpty(){
return first == null;
}
}

@ -0,0 +1,28 @@
package com.mashibing.apipassenger.mashibing.ch5;
/**
*
*/
public class Node {
//数据域
public long data;
//结点域指针域下一个节点的引用
public Node next;
public Node previous;
public Node(long value){
this.data = value;
}
/**
*
*/
public void display(){
System.out.print(data + " ");
}
}

@ -0,0 +1,19 @@
package com.mashibing.apipassenger.mashibing.ch5;
public class TestDoubleLinkList {
public static void main(String[] args) {
DoubleLinkList d1 = new DoubleLinkList();
d1.insertLast(45);
d1.insertLast(56);
d1.insertLast(90);
d1.display();
d1.deleteLast();
d1.display();
while(!d1.isEmpty()){
d1.deleteFirst();
d1.display();
}
}
}

@ -0,0 +1,26 @@
package com.mashibing.apipassenger.mashibing.ch5;
public class TestFirstLastLinkList {
public static void main(String[] args){
FirstLastLinkList f1 = new FirstLastLinkList();
/* f1.insertFirst(34);
f1.insertFirst(56);
f1.insertFirst(67);
f1.display();
f1.deleteFirst();
f1.deleteFirst();
f1.display();*/
f1.insertLast(56);
f1.insertLast(90);
f1.insertLast(12);
f1.insertFirst(34);
f1.insertFirst(56);
f1.insertFirst(67);
f1.display();
f1.deleteFirst();
f1.display();
}
}

@ -0,0 +1,12 @@
一,什么是双端链表。
链表中保存着对最后一个链结点引用的链表。
二,从头部进行插入
要对链表进行判断,如果为空则设置尾结点为新添加的结点。
三,从尾部进行插入
如果链表为空,则直接设置头节点为新添加的结点,否则设置尾结点的后一个结点为新添加结点
四,从头部进行删除
判断头节点是否有下一个结点如果没有则设置为结点为null。

@ -0,0 +1,28 @@
package com.mashibing.apipassenger.mashibing.test01;
import java.util.ArrayList;
import java.util.Collections;
import java.util.*;
public class Test {
public static void main(String[] args) {
List<String> list =new ArrayList<>();
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextLine()) { // 注意 while 处理多个 case
String a = in.nextLine();
int c = Integer.valueOf(a);
for(int i=0;i<c;i++){
String b= in.nextLine();
list.add(b);
}
Collections.sort(list);
for(String str:list){
System.out.println(str);
}
}
}
}

@ -0,0 +1,20 @@
package com.mashibing.apipassenger.mashibing.test01;
public class Test01 {
public static void main(String[] args){
int a =5;
String str = Integer.toString(a,2);
System.out.println(str);
char[] chars= str.toCharArray();
int count=0;
for(int i=0;i<chars.length;i++){
System.out.println(chars[i]);
if(chars[i] == '1'){
count++;
}
}
System.out.println(count);
}
}

@ -0,0 +1,37 @@
package com.mashibing.apipassenger.mashibing.test01;
import java.util.HashMap;
import java.util.Map;
public class Test02 {
public static void main(String[] args){
String paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.";
String[] banned = {"hit"};
paragraph=paragraph.toLowerCase().replace('!',' ');
paragraph=paragraph.replace('?',' ').replace('\'',' ').replace(',',' ').replace(';',' ').replace('.',' ').trim();
String[] s = paragraph.split(" ");
Map<String,Integer> map1=new HashMap<>();
Map<String,Integer> map2=new HashMap<>();
//被禁用的单词放入map1
for(String str:banned){
map1.put(str,1);
}
//把没有禁用的单词放入map2
for(String str : s){
if(!map1.containsKey(str)&&!str.equals("")){
map2.put(str,map2.getOrDefault(str,0)+1);
}
}
//在map2找出出现最多的单词
int max=-1;
String res=null;
for(String str:map2.keySet()){
if(map2.get(str)>max){
max=map2.get(str);
res=str;
}
}
System.out.println(res);
}
}

@ -0,0 +1,7 @@
package com.mashibing.apipassenger.mashibing.test01;
public class Test03 {
public static void main(String[] args) {
}
}

@ -0,0 +1,15 @@
package com.mashibing.apipassenger.mashibing.test01;
public class Test04 {
public static void main(String[] args) {
long a = 2000000014;
for(long i=2;i<=a;i++){
while(a % i==0){
System.out.print(i+" ");
a /= i;
}
}
}
}

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

@ -0,0 +1,15 @@
package com.mashibing.apipassenger.remote;
import com.mashibing.internal.common.dto.ResponseResult;
import com.mashibing.internal.common.response.NumberCodeResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient("service-verificationcode")
public interface ServiceVerificationCodeClient {
@RequestMapping(method = RequestMethod.GET,value = "/numberCode/{size}")
ResponseResult<NumberCodeResponse> getNumberCode(@PathVariable("size") int size);
}

@ -0,0 +1,17 @@
server:
port: 8081
spring:
cloud:
nacos:
discovery:
access-key: 127.0.0.1:8848
application:
name: api-passenger
redis:
host: 127.0.0.1
port: 6379
database: 0

@ -0,0 +1,102 @@
package test;
import org.junit.Test;
import java.util.Arrays;
public class Test01 {
static void print(int[] arr){
for(int i =0;i<arr.length;i++){
System.out.print(arr[i] + " ");
}
}
static void swap(int[] arr,int i,int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static int partition(int[] arr,int leftBound,int rightBound){
int pivot = arr[rightBound];
int left = leftBound;
int right = rightBound -1;
while(left <= right){
while(left<=right && arr[left] <= pivot){
left++;
}
while( left<=right && arr[right]> pivot){
right--;
}
if(left<right){
swap(arr,left,right);
}
}
swap(arr,left,rightBound);
return left;
}
public static void sort(int[] arr,int leftBound,int rightBound){
if(leftBound>= rightBound){
return;
}
int mid= partition(arr,leftBound,rightBound);
sort(arr,leftBound,mid -1);
sort(arr,mid+1,rightBound);
}
@Test
public void test01(){
/**
* 1.
* 2.
* 3.
*/
int[] arr = {7,3,2,8,1,9,5,4,6,10};
sort(arr,0,arr.length -1);
print(arr);
}
@Test
public void test02(){
int[] arr = {2,4,2,3,7,1,1,0,0,5,6,9,8,5,7,4,0,9};
int[] result = sort(arr);
System.out.println(Arrays.toString(result));
}
static int[] sort(int[] arr){
int[] result = new int[arr.length];
int[] count = new int[10];
for(int i=0;i<arr.length;i++){
count[arr[i]]++;
}
System.out.println(Arrays.toString(count));
// for(int i =0,j=0;i<count.length;i++){
// while(count[i]-->0){
// result[j++]=i;
// }
//
// }
for(int i=1;i<count.length;i++){
count[i] = count[i]+count[i-1];
}
for(int i =arr.length-1;i>=0;i--){
result[--count[arr[i]]]=arr[i];
}
return result;
}
@Test
public void test03(){
StringBuilder result = new StringBuilder();
result.append('a');
result.append('b');
System.out.println(result.toString());
if(result.length()>0){
result.deleteCharAt(result.length()-1);
}
System.out.println(result.toString());
}
}

@ -0,0 +1,176 @@
package test;
import org.junit.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class test02 {
@Test
public void test01() {
int[] arr = {421, 240, 115, 532, 305, 430, 124};
// int[] result = sort(arr);
// System.out.println(Arrays.toString(result));
}
/*public static int[] sort(int[] arr) {
int[] result = new int[arr.length];
int[] count = new int[10];
for(int i=0;i<3;i++){
int division = (int)Math.pow(10,i);
System.out.println(division);
}
}*/
@Test
public void test02() {
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 6};
int x1 = 0;
for (int i = 1; i <= 10; i++) {
x1 = (x1 ^ i);
}
System.out.println(x1);
for (int i = 0; i < 11; i++) {
x1 = x1 ^ arr[i];
}
System.out.println(x1);
int[] helper = new int[11];
for (int i = 0; i < 11; i++) {
helper[arr[i]]++;
}
for (int i = 0; i < 11; i++) {
if (helper[i] == 2) {
System.out.println(i);
break;
}
}
}
@Test
public void test03() {
int N = 9;
int count = 0;
while (N != 0) {
N = ((N - 1) & N);
count++;
}
System.out.println(count);
}
@Test
public void test04() {
/**
* 2
*/
int N = 8;
if (((N - 1) & N) == 0) {
System.out.println(N + ":是2的整数次方");
} else {
System.out.println(N + "不是2的整数次方");
}
}
@Test
public void test05() {
/**
* 5
*/
int i = 6;
int out = i & 0xaaaaaaaa;
int ji = i & 0x55555555;
System.out.println(out >> 1 ^ ji << 1);
}
@Test
public void test06() {
/**
* 60-1
* 01(0.625)double,
* 0.101
* 0.50.250.125.
* 32ERROR"
*/
double num = 0.625;
StringBuilder sb = new StringBuilder("0.");
while (num > 0) {
//乘2挪整
double r = num * 2;
//判断整数部分
if (r >= 1) {
sb.append("1");
//消掉整数部分
num = r - 1;
} else {
sb.append("0");
num = r;
}
if (sb.length() > 34) {
System.out.println("ERROR");
return;
}
}
System.out.println(sb.toString());
}
@Test
public void test07() {
/**
* 1k1
*
*/
int[] arr = {2, 2, 2, 9, 7, 7, 7, 3, 3, 3, 6, 6, 6, 0, 0, 0};
int len = arr.length;
char[][] kRadix = new char[len][];
int k = 3;
int maxLen = 0;
//转成k进制字符数组
//对于每个数字
for (int i = 0; i < len; i++) {
//求每个数字的三进制字符串并反转,然后转为字符数组
kRadix[i] = new StringBuilder(Integer.toString(arr[i], k)).reverse().toString().toCharArray();
if (kRadix[i].length > maxLen) {
maxLen = kRadix[i].length;
}
}
int[] resArr = new int[maxLen];
for (int j = 0; j < len; j++) {
//不进位加法
for (int m = 0; m < maxLen; m++) {
if (m >= kRadix[j].length) {
resArr[m] += 0;
} else {
resArr[m] += (kRadix[j][m] - '0');
}
}
}
int res = 0;
for (int j = 0; j < maxLen; j++) {
res += (resArr[j] % k) * (int) (Math.pow(k, j));
}
System.out.println(res);
}
@Test
public void test08(){
/**
* 1k1
*
*/
int[] arr = {2, 2, 2, 9, 7, 7, 7, 3, 3, 3, 6, 6, 6, 0, 0, 0};
Map<Integer,Integer> map = new HashMap<>();
for(int i=0;i<arr.length;i++){
map.put(arr[i],map.getOrDefault(arr[i],0)+1);
}
for(int i=0;i<arr.length;i++){
if(map.get(arr[i])==1){
System.out.println(arr[i]);
}
}
}
}

@ -0,0 +1,17 @@
server:
port: 8081
spring:
cloud:
nacos:
discovery:
access-key: 127.0.0.1:8848
application:
name: api-passenger
redis:
host: 127.0.0.1
port: 6379
database: 0

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save