diff --git a/src/main/java/com/hnucm/c202201020141/Api.java b/src/main/java/com/hnucm/c202201020141/Api.java index 766f845..9c20af1 100644 --- a/src/main/java/com/hnucm/c202201020141/Api.java +++ b/src/main/java/com/hnucm/c202201020141/Api.java @@ -4,11 +4,16 @@ import java.util.Map; import retrofit2.Call; import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; import retrofit2.http.POST; public interface Api { @POST("login") Call login(@Body Map map); + @GET("/system/doctor/list") + Call doctorlist(@Header("Authorization")String token); - + @GET("/system/doctor/list") + Call departmentlist(@Header("Authorization")String token); } diff --git a/src/main/java/com/hnucm/c202201020141/DepartmentResult.java b/src/main/java/com/hnucm/c202201020141/DepartmentResult.java new file mode 100644 index 0000000..0a17699 --- /dev/null +++ b/src/main/java/com/hnucm/c202201020141/DepartmentResult.java @@ -0,0 +1,23 @@ +package com.hnucm.c202201020141; + +import java.util.List; + +public class DepartmentResult { + + public Integer total; + public Integer code; + public String msg; + public List rows; + + public static class RowsDTO { + public Object createBy; + public Object createTime; + public Object updateBy; + public Object updateTime; + public Object remark; + public Integer id; + public String department; + public String number; + public String picture; + } +} diff --git a/src/main/java/com/hnucm/c202201020141/DoctorResult.java b/src/main/java/com/hnucm/c202201020141/DoctorResult.java new file mode 100644 index 0000000..471582e --- /dev/null +++ b/src/main/java/com/hnucm/c202201020141/DoctorResult.java @@ -0,0 +1,24 @@ +package com.hnucm.c202201020141; + +import java.util.List; + +public class DoctorResult { + + public Integer total; + public Integer code; + public String msg; + public List rows; + + public static class RowsDTO { + public Object createBy; + public Object createTime; + public Object updateBy; + public Object updateTime; + public Object remark; + public Integer id; + public String doctor; + public String expert; + public String cost; + public String picture; + } +} diff --git a/src/main/java/com/hnucm/c202201020141/HomeActivity2.java b/src/main/java/com/hnucm/c202201020141/HomeActivity2.java index 5b5156c..50368e8 100644 --- a/src/main/java/com/hnucm/c202201020141/HomeActivity2.java +++ b/src/main/java/com/hnucm/c202201020141/HomeActivity2.java @@ -1,6 +1,8 @@ package com.hnucm.c202201020141; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -151,6 +153,29 @@ public class HomeActivity2 extends AppCompatActivity { holder.Layout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { +// http://10.138.6.102:8080/system/departments/list + SharedPreferences sharedPreferences= getSharedPreferences("data", Context.MODE_PRIVATE); + String token=sharedPreferences.getString("token",""); + retrofit2.Call departmentResultCall= RetrofitUtils.getRetrofit("http://10.138.6.102:8080/system/departments/list/") + .create(Api.class) + .departmentlist("Bearer "+token); + departmentResultCall.enqueue(new retrofit2.Callback() { + @Override + public void onResponse(retrofit2.Call call, retrofit2.Response response) { + DepartmentResult departmentResult=response.body(); + if (departmentResult.code==200){ + + }else{ + + } + } + + @Override + public void onFailure(retrofit2.Call call, Throwable t) { + + } + }); + Intent intent=new Intent(HomeActivity2.this, HomeActivity3.class); startActivity(intent); } diff --git a/src/main/java/com/hnucm/c202201020141/HomeFragment.java b/src/main/java/com/hnucm/c202201020141/HomeFragment.java index 754d6e0..25ae8b1 100644 --- a/src/main/java/com/hnucm/c202201020141/HomeFragment.java +++ b/src/main/java/com/hnucm/c202201020141/HomeFragment.java @@ -1,7 +1,9 @@ package com.hnucm.c202201020141; import android.app.AlertDialog; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import androidx.fragment.app.Fragment; @@ -20,6 +22,11 @@ import com.youth.banner.indicator.CircleIndicator; import java.util.ArrayList; import java.util.List; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + public class HomeFragment extends Fragment { @@ -52,6 +59,29 @@ public class HomeFragment extends Fragment { textView27.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + SharedPreferences sharedPreferences= requireContext().getSharedPreferences("data", Context.MODE_PRIVATE); + String token=sharedPreferences.getString("token",""); + Call doctorResultCall= RetrofitUtils.getRetrofit("http://10.138.6.102:8080/system/doctor/list/") + .create(Api.class) + .doctorlist("Bearer "+token); + doctorResultCall.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + DoctorResult doctorResult=response.body(); + if (doctorResult.code==200){ + + }else{ + + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + + Intent intent=new Intent(getActivity(),HomeActivity2.class); startActivity(intent); } diff --git a/src/main/java/com/hnucm/c202201020141/RetrofitUtils.java b/src/main/java/com/hnucm/c202201020141/RetrofitUtils.java new file mode 100644 index 0000000..faf4cc3 --- /dev/null +++ b/src/main/java/com/hnucm/c202201020141/RetrofitUtils.java @@ -0,0 +1,37 @@ +package com.hnucm.c202201020141; + +import android.util.Log; +import okhttp3.logging.HttpLoggingInterceptor; +import okhttp3.OkHttpClient; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +public class RetrofitUtils { + + public static Retrofit getRetrofit(String url) { + //日志显示级别 + HttpLoggingInterceptor.Level level= HttpLoggingInterceptor.Level.BODY; + //新建log拦截器 + HttpLoggingInterceptor loggingInterceptor=new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { + @Override + public void log(String message) { + Log.d("RetrofitMessage","OkHttp====Message:"+message); + } + }); + loggingInterceptor.setLevel(level); + //定制OkHttp + OkHttpClient.Builder httpClientBuilder = new OkHttpClient + .Builder(); + //OkHttp进行添加拦截器loggingInterceptor + httpClientBuilder.addInterceptor(loggingInterceptor); + + Retrofit retrofit = new Retrofit.Builder() + .baseUrl(url) + .addConverterFactory(GsonConverterFactory.create()) + .client( httpClientBuilder.build()) + .build(); + + return retrofit; + } + +} \ No newline at end of file