111 lines
3.2 KiB
Java
111 lines
3.2 KiB
Java
package com.arpa.hndahesudintocctmsdriver.service;
|
||
|
||
import android.app.Service;
|
||
import android.content.Context;
|
||
import android.content.Intent;
|
||
import android.os.Handler;
|
||
import android.os.IBinder;
|
||
import android.util.Log;
|
||
|
||
import androidx.annotation.Nullable;
|
||
|
||
import com.arpa.hndahesudintocctmsdriver.util.log.LogUtil;
|
||
import com.google.gson.Gson;
|
||
import com.arpa.hndahesudintocctmsdriver.bean.BaseBean;
|
||
import com.arpa.hndahesudintocctmsdriver.request.HuoYuanRequset;
|
||
import com.arpa.hndahesudintocctmsdriver.request.bean.TrackInputBean;
|
||
import com.arpa.hndahesudintocctmsdriver.util.location.LocationGDUtil;
|
||
import com.arpa.hndahesudintocctmsdriver.util.sp.SPUtil;
|
||
import com.arpa.hndahesudintocctmsdriver.util.cache.CacheGroup;
|
||
import com.arpa.hndahesudintocctmsdriver.util.http.RequsetCodeConstants;
|
||
|
||
import java.util.Timer;
|
||
import java.util.TimerTask;
|
||
|
||
/**
|
||
* @author hlh
|
||
* @version 1.0.0
|
||
* @date 2021/8/13 18:52
|
||
* @description:上传司机轨迹位置
|
||
*/
|
||
public class TrackService extends Service {
|
||
|
||
private Context con;
|
||
private TrackInputBean tib=new TrackInputBean();
|
||
private LocationGDUtil l;
|
||
private int timeSum=1000*60*3;
|
||
private String snn="";
|
||
private Gson gson=new Gson();
|
||
private HuoYuanRequset hyr;
|
||
|
||
private Handler hd=new Handler(msg -> {
|
||
switch (msg.what){
|
||
case RequsetCodeConstants.SUCCESS:
|
||
if(CacheGroup.cacheList.get("genzong")!=null){
|
||
BaseBean bb=gson.fromJson(CacheGroup.cacheList.get("genzong"),BaseBean.class);
|
||
if(bb.getCode()==200){
|
||
LogUtil.e("--轨迹上传--","成功");
|
||
}else{
|
||
LogUtil.e("--轨迹上传失败:--",bb.getMsg());
|
||
}
|
||
CacheGroup.cacheList.remove("genzong");
|
||
}
|
||
break;
|
||
case LocationGDUtil.RES:
|
||
genzong();
|
||
break;
|
||
}
|
||
return false;
|
||
});
|
||
|
||
@Nullable
|
||
@Override
|
||
public IBinder onBind(Intent intent) {return null; }
|
||
|
||
@Override
|
||
public void onCreate() {
|
||
super.onCreate();
|
||
con=this;
|
||
hyr=new HuoYuanRequset(con,hd);
|
||
LogUtil.e("开始循环上传,等待100ms","-----");
|
||
new Timer().schedule(new TimerTask() {
|
||
@Override
|
||
public void run() {
|
||
snn=SPUtil.getSP(con,"order","ShippingNoteNumber");
|
||
if(!snn.equals("")) {
|
||
l = new LocationGDUtil(con, hd);
|
||
l.onCreate();
|
||
}else{
|
||
onDestroy();
|
||
}
|
||
}
|
||
},100,timeSum);
|
||
}
|
||
|
||
//开始
|
||
@Override
|
||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||
LogUtil.e("服务开启","-----");
|
||
return START_STICKY;
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onDestroy() {
|
||
super.onDestroy();
|
||
}
|
||
|
||
public void genzong(){
|
||
//经度
|
||
tib.setLatitude(l.getLatitude()+"");
|
||
//纬度
|
||
tib.setLongitude(l.getLongitude()+"");
|
||
LogUtil.e("经度",l.getLatitude()+"");
|
||
LogUtil.e("维度",l.getLongitude()+"");
|
||
//单号
|
||
tib.setShippingNoteNumber(snn);
|
||
hyr.trackTracking(tib);
|
||
}
|
||
|
||
}
|