492 lines
18 KiB
Java
492 lines
18 KiB
Java
package com.arpa.hndahesudintocctmsdriver.util;
|
|
|
|
import static com.dahe.mylibrary.utils.BaseSPUtils.NEW_LJ_TOKEN;
|
|
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import com.arpa.hndahesudintocctmsdriver.bean.GDImage;
|
|
import com.arpa.hndahesudintocctmsdriver.bean.GDLocation;
|
|
import com.arpa.hndahesudintocctmsdriver.constant.NewLJConstant;
|
|
import com.arpa.hndahesudintocctmsdriver.request.bean.newlj.InvoiceBean;
|
|
import com.arpa.hndahesudintocctmsdriver.request.bean.newlj.LjTokenBean;
|
|
import com.arpa.hndahesudintocctmsdriver.request.bean.newlj.PickupBean;
|
|
import com.arpa.hndahesudintocctmsdriver.request.bean.newlj.ShipmentStatusBean;
|
|
import com.arpa.hndahesudintocctmsdriver.request.bean.newlj.UpimgBean;
|
|
import com.arpa.hndahesudintocctmsdriver.request.net.BaseObserver;
|
|
import com.arpa.hndahesudintocctmsdriver.request.net.DataManager;
|
|
import com.arpa.hndahesudintocctmsdriver.request.net.RxHttpCallBack;
|
|
import com.dahe.mylibrary.callback.OnGDDownloadResultListener;
|
|
import com.dahe.mylibrary.callback.OnGDResultListener;
|
|
import com.dahe.mylibrary.net.CommonResponseBean;
|
|
import com.dahe.mylibrary.utils.ToastUtils;
|
|
import com.express.mdp.Api;
|
|
|
|
|
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
|
|
|
/**
|
|
* @ClassName NewLJUtils
|
|
* @Author john
|
|
* @Date 2024/11/25 09:53
|
|
* @Description TODO
|
|
*/
|
|
public class NewLJUtils {
|
|
|
|
|
|
private static class SingletonHolder {
|
|
private static final NewLJUtils INSTANCE = new NewLJUtils();
|
|
}
|
|
|
|
private NewLJUtils() {
|
|
}
|
|
|
|
public static final NewLJUtils getInstance() {
|
|
return SingletonHolder.INSTANCE;
|
|
}
|
|
|
|
public void getToken(Context ctx) {
|
|
LjTokenBean ljTokenBean = new LjTokenBean();
|
|
ljTokenBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
|
ljTokenBean.setEnterpriseIdentity(NewLJConstant.ENTER_PRISE_IDENTITY);
|
|
ljTokenBean.setEnterpriseKey(NewLJConstant.ENTER_PRISE_KEY);
|
|
|
|
DataManager.getInstance().getToken(ljTokenBean)
|
|
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
SPUtils.put(ctx, NEW_LJ_TOKEN, t.getToken());
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
/**
|
|
* 运单提货
|
|
*
|
|
* @param ctx
|
|
* @param shipmentCode
|
|
* @param location
|
|
*/
|
|
public void pickUp(Context ctx, String shipmentCode, GDLocation location, OnGDResultListener listener) {
|
|
if (TextUtils.isEmpty(shipmentCode)) {
|
|
ToastUtils.showToast(ctx, "运单号不能为空");
|
|
return;
|
|
}
|
|
|
|
if (Double.isNaN(location.getBaiduLatitude()) || Double.isNaN(location.getBaiduLongitude())) {
|
|
ToastUtils.showToast(ctx, "经纬度不能为空");
|
|
return;
|
|
}
|
|
PickupBean pickupBean = new PickupBean();
|
|
pickupBean.setShipmentCode(shipmentCode);
|
|
pickupBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
|
pickupBean.setLocation(location);
|
|
DataManager.getInstance().pickup(pickupBean)
|
|
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
if (listener != null) {
|
|
listener.onSuccess();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCodeError(Context mContext, CommonResponseBean<CommonResponseBean> t) {
|
|
super.onCodeError(mContext, t);
|
|
if (listener != null) {
|
|
listener.onFailure(t.getCode() + "", t.getMessage());
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
/**
|
|
* 运单卸货
|
|
*
|
|
* @param ctx
|
|
* @param shipmentCode
|
|
* @param location
|
|
*/
|
|
public void unload(Context ctx, String shipmentCode, GDLocation location, OnGDResultListener listener) {
|
|
if (TextUtils.isEmpty(shipmentCode)) {
|
|
ToastUtils.showToast(ctx, "运单号不能为空");
|
|
return;
|
|
}
|
|
|
|
if (Double.isNaN(location.getBaiduLatitude()) || Double.isNaN(location.getBaiduLongitude())) {
|
|
ToastUtils.showToast(ctx, "经纬度不能为空");
|
|
return;
|
|
}
|
|
|
|
PickupBean pickupBean = new PickupBean();
|
|
pickupBean.setShipmentCode(shipmentCode);
|
|
pickupBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
|
pickupBean.setLocation(location);
|
|
DataManager.getInstance().unload(pickupBean)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
if (listener != null) {
|
|
listener.onSuccess();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCodeError(Context mContext, CommonResponseBean<CommonResponseBean> t) {
|
|
super.onCodeError(mContext, t);
|
|
if (listener != null) {
|
|
listener.onFailure(t.getCode() + "", t.getMessage());
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
/**
|
|
* 运单签收
|
|
*
|
|
* @param ctx
|
|
* @param shipmentCode
|
|
* @param location
|
|
*/
|
|
public void sign(Context ctx, String shipmentCode, GDLocation location, OnGDResultListener listener) {
|
|
if (TextUtils.isEmpty(shipmentCode)) {
|
|
ToastUtils.showToast(ctx, "运单号不能为空");
|
|
return;
|
|
}
|
|
|
|
if (Double.isNaN(location.getBaiduLatitude()) || Double.isNaN(location.getBaiduLongitude())) {
|
|
ToastUtils.showToast(ctx, "经纬度不能为空");
|
|
return;
|
|
}
|
|
|
|
PickupBean pickupBean = new PickupBean();
|
|
pickupBean.setShipmentCode(shipmentCode);
|
|
pickupBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
|
pickupBean.setLocation(location);
|
|
DataManager.getInstance().sign(pickupBean)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
if (listener != null) {
|
|
listener.onSuccess();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCodeError(Context mContext, CommonResponseBean<CommonResponseBean> t) {
|
|
super.onCodeError(mContext, t);
|
|
if (listener != null) {
|
|
listener.onFailure(t.getCode() + "", t.getMessage());
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
/**
|
|
* 运单回单
|
|
*
|
|
* @param ctx
|
|
* @param shipmentCode
|
|
* @param location
|
|
*/
|
|
public void pod(Context ctx, String shipmentCode, GDLocation location, OnGDResultListener listener) {
|
|
if (TextUtils.isEmpty(shipmentCode)) {
|
|
ToastUtils.showToast(ctx, "运单号不能为空");
|
|
return;
|
|
}
|
|
|
|
if (Double.isNaN(location.getBaiduLatitude()) || Double.isNaN(location.getBaiduLongitude())) {
|
|
ToastUtils.showToast(ctx, "经纬度不能为空");
|
|
return;
|
|
}
|
|
|
|
PickupBean pickupBean = new PickupBean();
|
|
pickupBean.setShipmentCode(shipmentCode);
|
|
pickupBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
|
pickupBean.setLocation(location);
|
|
DataManager.getInstance().pod(pickupBean)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
if (listener != null) {
|
|
listener.onSuccess();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCodeError(Context mContext, CommonResponseBean<CommonResponseBean> t) {
|
|
super.onCodeError(mContext, t);
|
|
if (listener != null) {
|
|
listener.onFailure(t.getCode() + "", t.getMessage());
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
/**
|
|
* 运单提货照片上传
|
|
*
|
|
* @param ctx
|
|
* @param shipmentCode
|
|
* @param imageDTO
|
|
*/
|
|
public void uploadPickupImage(Context ctx, String shipmentCode, GDImage imageDTO, OnGDResultListener listener) {
|
|
if (TextUtils.isEmpty(shipmentCode)) {
|
|
ToastUtils.showToast(ctx, "运单号不能为空");
|
|
return;
|
|
}
|
|
|
|
if (TextUtils.isEmpty(imageDTO.getFileName())) {
|
|
ToastUtils.showToast(ctx, "照片不能为空");
|
|
return;
|
|
}
|
|
|
|
UpimgBean pickupBean = new UpimgBean();
|
|
pickupBean.setShipmentCode(shipmentCode);
|
|
pickupBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
|
pickupBean.setImage(imageDTO);
|
|
DataManager.getInstance().uploadPickupImage(pickupBean)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
if (listener != null) {
|
|
listener.onSuccess();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCodeError(Context mContext, CommonResponseBean<CommonResponseBean> t) {
|
|
super.onCodeError(mContext, t);
|
|
if (listener != null) {
|
|
listener.onFailure(t.getCode() + "", t.getMessage());
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
/**
|
|
* 运单卸货照片上传
|
|
*
|
|
* @param ctx
|
|
* @param shipmentCode
|
|
* @param imageDTO
|
|
*/
|
|
public void uploadUnloadImage(Context ctx, String shipmentCode, GDImage imageDTO, OnGDResultListener listener) {
|
|
if (TextUtils.isEmpty(shipmentCode)) {
|
|
ToastUtils.showToast(ctx, "运单号不能为空");
|
|
return;
|
|
}
|
|
|
|
if (TextUtils.isEmpty(imageDTO.getFileName())) {
|
|
ToastUtils.showToast(ctx, "照片不能为空");
|
|
return;
|
|
}
|
|
|
|
UpimgBean pickupBean = new UpimgBean();
|
|
pickupBean.setShipmentCode(shipmentCode);
|
|
pickupBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
|
pickupBean.setImage(imageDTO);
|
|
DataManager.getInstance().uploadUnloadImage(pickupBean)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
if (listener != null) {
|
|
listener.onSuccess();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCodeError(Context mContext, CommonResponseBean<CommonResponseBean> t) {
|
|
super.onCodeError(mContext, t);
|
|
if (listener != null) {
|
|
listener.onFailure(t.getCode() + "", t.getMessage());
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
/**
|
|
* 运单回单照片上传
|
|
*
|
|
* @param ctx
|
|
* @param shipmentCode
|
|
* @param imageDTO
|
|
*/
|
|
public void uploadPODImage(Context ctx, String shipmentCode, GDImage imageDTO, OnGDResultListener listener) {
|
|
if (TextUtils.isEmpty(shipmentCode)) {
|
|
ToastUtils.showToast(ctx, "运单号不能为空");
|
|
return;
|
|
}
|
|
|
|
if (TextUtils.isEmpty(imageDTO.getFileName())) {
|
|
ToastUtils.showToast(ctx, "照片不能为空");
|
|
return;
|
|
}
|
|
|
|
UpimgBean pickupBean = new UpimgBean();
|
|
pickupBean.setShipmentCode(shipmentCode);
|
|
pickupBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
|
pickupBean.setImage(imageDTO);
|
|
DataManager.getInstance().uploadPODImage(pickupBean)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
if (listener != null) {
|
|
listener.onSuccess();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCodeError(Context mContext, CommonResponseBean<CommonResponseBean> t) {
|
|
super.onCodeError(mContext, t);
|
|
if (listener != null) {
|
|
listener.onFailure(t.getCode() + "", t.getMessage());
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
/**
|
|
* 同意发票申请
|
|
*
|
|
* @param ctx
|
|
* @param shipmentCode
|
|
* @param invoiceBean
|
|
*/
|
|
public void confirmInvoice(Context ctx, String shipmentCode, InvoiceBean invoiceBean, OnGDResultListener listener) {
|
|
|
|
DataManager.getInstance().confirmInvoice(invoiceBean)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
if (listener != null) {
|
|
listener.onSuccess();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCodeError(Context mContext, CommonResponseBean<CommonResponseBean> t) {
|
|
super.onCodeError(mContext, t);
|
|
if (listener != null) {
|
|
listener.onFailure(t.getCode() + "", t.getMessage());
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
|
|
/**
|
|
* 运单状态查询
|
|
*
|
|
* @param ctx
|
|
* @param shipmentCode
|
|
*/
|
|
public void getShipmentStatus(Context ctx, String shipmentCode, OnGDDownloadResultListener listener) {
|
|
ShipmentStatusBean shipmentStatusBean = new ShipmentStatusBean();
|
|
shipmentStatusBean.setShipmentCode(shipmentCode);
|
|
shipmentStatusBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
|
DataManager.getInstance().getShipmentStatus(shipmentStatusBean)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
if (listener != null) {
|
|
listener.onSuccess(t.getStatusCode());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCodeError(Context mContext, CommonResponseBean<CommonResponseBean> t) {
|
|
super.onCodeError(mContext, t);
|
|
if (listener != null) {
|
|
listener.onFailure(t.getCode() + "", t.getMessage());
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
public void getPODImageNames(Context ctx, String shipmentCode){
|
|
ShipmentStatusBean shipmentStatusBean = new ShipmentStatusBean();
|
|
shipmentStatusBean.setShipmentCode(shipmentCode);
|
|
shipmentStatusBean.setEnterpriseCode(NewLJConstant.ENTER_PRISE_CODE);
|
|
DataManager.getInstance().getPODImageNames(shipmentStatusBean)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new BaseObserver(ctx, new RxHttpCallBack<CommonResponseBean>() {
|
|
@Override
|
|
public void onSuccess(CommonResponseBean t) {
|
|
super.onSuccess(t);
|
|
System.out.println("sadf");
|
|
}
|
|
|
|
@Override
|
|
public void onCodeError(Context mContext, CommonResponseBean<CommonResponseBean> t) {
|
|
super.onCodeError(mContext, t);
|
|
System.out.println("sadf");
|
|
}
|
|
}));
|
|
}
|
|
|
|
/**
|
|
* 开启位置上传
|
|
* @param act
|
|
*/
|
|
public void startLocationService(AppCompatActivity act){
|
|
try {
|
|
Api.setBaseUrl("https://kehui56.cn/api","https://api.kehui56.cn/api");
|
|
Api.startLocationService(act, NewLJConstant.ENTER_PRISE_CODE, s -> {
|
|
Log.e("位置上报", s);
|
|
});
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 关闭定位服务
|
|
*/
|
|
public void stopLocationService(){
|
|
Api.stopLocationService();
|
|
}
|
|
|
|
}
|