Explorar o código

Merge branch 'master' into master_925

guilin hai 1 mes
pai
achega
61a579dfa5

+ 17 - 1
app/src/main/java/com/fxy/common/AsyncFileUpload.java

@@ -18,6 +18,7 @@ import com.fxy.constant.EventCode;
 import com.fxy.constant.SPCache;
 import com.fxy.net.MyDialogCallback;
 import com.fxy.realm.AsyncUploadRealm;
+import com.fxy.utils.UploadUtils;
 import com.luck.picture.lib.entity.LocalMedia;
 import com.lzy.okgo.OkGo;
 import com.lzy.okgo.model.Response;
@@ -250,6 +251,16 @@ public class AsyncFileUpload {
         realmResults.load();
         return  realmResults.size();
     }
+    public int getAllAwaitNum(Integer[] pushStatus){
+
+        RealmResults<AsyncUploadRealm> realmResults  = mRealm.where(AsyncUploadRealm.class)
+                .equalTo("isDelete",0)
+                .in("pushStatus",pushStatus)
+                .sort("pushStatus").findAll();
+        realmResults.load();
+        return  realmResults.size();
+    }
+
 
     //存储数据问题
     private void asyncUpload(){
@@ -280,7 +291,12 @@ public class AsyncFileUpload {
 
     public void setStartUpload(){
         allowUpload = true;
-        asyncUpload();
+        if (UploadUtils.getUploadExists(mContext)){
+            asyncUpload();
+        }else{
+            XLog.d("AsyncFileUpload当前有任务正在上传");
+        }
+
     }
 
     public void setStopUpload(){

+ 21 - 90
app/src/main/java/com/fxy/common/AsyncPictureUpload.java

@@ -52,6 +52,7 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 import io.reactivex.functions.Consumer;
@@ -105,7 +106,7 @@ public class AsyncPictureUpload {
     private boolean allowUpload = true;
 
     //
-    private boolean isAllRe =false;
+    private boolean isAllRePush =false;
 
     private boolean debug = false;
     public void setDebug(boolean debug) {
@@ -185,7 +186,7 @@ public class AsyncPictureUpload {
      */
     public int getAllAwaitNum(){
 
-        if (isAllRe){
+        if (isAllRePush){
             Integer[] pushStatus = {0,1};
             RealmResults<AsyncUploadRealm> realmResults  = mRealm.where(AsyncUploadRealm.class)
                     .equalTo("isDelete",0)
@@ -389,6 +390,7 @@ public class AsyncPictureUpload {
     //存储数据问题
     private void asyncUpload(){
 
+
         if (!getIsNetwork()){
             //无网络时在请求检查是否有网络
             return;
@@ -411,97 +413,26 @@ public class AsyncPictureUpload {
     //临时处理数据用
     private void tmpData(){
         if (awaitUploadList.size()==0 && debug){
-            String[] ossUrlList = {
-                    "/uat/fxy/android/tally/20240924/57058c6a-6f59-4e6d-a93c-7a8044f9a721.JPEG"
-
-                    ,"/prod/fxy/android/detection/20240923/d3e5552e-344c-4c74-be91-468cbb22f22c.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/893d8514-de5a-44bd-822a-c82959d11913.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/d0346866-d994-476c-8229-06aadb118eea.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/8d4f6893-e325-433a-9f78-0844d7b6b331.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/ac92069b-895e-45ad-b507-0494336be03a.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/3f2cd16c-59fb-40d5-bcf3-c969f7cbbb5c.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/47ef4d43-6fe6-4040-a5ec-8b9732ba5100.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/39284eae-b033-4e7d-a17c-e85c43931b6c.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/bd8c0f51-c211-458e-80d2-591b3fd7f25b.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/33f57a98-b86d-4b11-aca5-142042acfa77.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/4b611cbf-6273-43e1-81b0-120cf86dca53.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/63910671-cda0-4baf-a430-8bd3776c199a.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/b7e4125c-1c9b-4146-a11d-f2685c18e51f.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/5aeab08a-e938-4645-919b-41bcf3791502.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/f2d52733-2e21-4a54-9134-8cdf2ea2557b.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/0db0c21d-7b24-4781-95de-102ef7845ec8.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/3f81cbae-1b1e-4c6c-8f11-8a1c7c786f2f.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/289d314e-ad49-4c42-8be9-8156e6c673bd.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/73b82d21-1722-4692-94f5-b001c0b36fe9.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/9bd4bebb-04a4-4999-aefc-11092bafe653.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/9124f3ce-ab63-43f2-9e7c-d1b8fe037e65.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/b4931917-6851-4c18-82d3-f9010b81d84b.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/dbcc7133-793c-441e-9ef8-d4126372fc3d.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/cac07313-17e7-4ec4-b73b-cb8e42d171fa.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/e81da115-731b-418d-ba6d-ceac8f4eba7e.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/fdc1ee7d-1a56-4ee7-ac93-adba19df2845.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/92ccee22-a2ff-4e09-a836-238a8dc1f1cc.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/f9e6dcb4-62bd-425b-baf2-8db75c72223d.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/fe5fe3a3-595d-4127-96d1-6671e356a4fd.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/8bdc775d-bbd8-433d-a757-bf1523c9d3ff.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/29fc2776-9bdd-4c61-bf6e-21d1a6928bdc.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/e910bfbf-4110-4b96-a711-1323d76763fe.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/bfa8001a-c5e7-4db4-bd16-1d977fb9dae5.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/1fab9a47-51ee-4e73-9058-0a65e147d557.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/9d1a3561-4918-40fa-a44a-21a552936182.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/ce70f7f9-bcc1-452a-b4cf-cd583b4f62bf.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/68e40cfe-9e64-4258-8fb5-c3c160942247.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/4148331e-0b6e-4343-8fcf-a1f8e4ec8d8a.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/d5ceb788-7f9e-41c5-921f-a4ea4b7d17f8.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/2b05c0fe-8a1e-4fa3-8481-58877b6eda5e.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/dda38490-feaf-42d3-b6f9-c260a4915cc0.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/74587b04-3a0f-4d60-a009-7b6d77d7d302.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/d2feeeee-5078-49cc-934f-cedc794c8888.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/d6b76b2c-d778-4fa2-9485-c5f34142c7ce.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/b156f5a8-74a4-4329-9791-463acebabf34.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/56ac3bd7-3e06-4b1f-84c0-ff83571cc4d5.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/7f296e23-309a-4453-96b8-66403b04b73a.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/20cd6d0d-73dd-4ecf-b8e8-34110a0fa619.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/96a7b5ef-cbcf-4550-89b3-fea48579e34e.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/06aef90f-2714-49c2-8371-02ea218b7962.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/a50fc133-9a01-4cb6-97e4-476c93d86723.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/1f4218ee-3fe2-47dd-a9f9-ac65fa00c44c.JPEG"
-                    ,"/prod/fxy/android/detection/20240924/0022e008-ba82-4e0e-9c80-4888a22c7c7e.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/c31f4fe2-e797-4926-8cd5-15db2e5eac59.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/4498de19-c6b2-44f3-b37d-ea0989230ba1.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/df7e573a-121c-46cc-bdfb-311c1a4b6a5e.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/9e4dbdc0-8a75-4518-9cf7-9b0194a42cde.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/9021c9b5-e17c-49c1-85d9-7773be136c7b.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/e7fe892c-c26f-4849-9957-f9bdf34a5f29.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/37e739c0-a2bc-4d86-a379-a3d00b773d41.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/2a301b28-9ced-460b-9e2c-da6520c39518.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/47da0be7-d528-4fc2-ad3d-cad9f4f456af.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/e46b2289-2d3a-4709-860c-6a48e48611f4.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/70b2c33d-7991-4cf5-99d6-69ee21f0200f.JPEG"
-                    ,"/prod/fxy/android/detection/20240923/c0065364-7fdc-4eb5-be13-8c630ecf3b59.JPEG"
-            };
-            long timestamp = getNextTimestamp(-6);
-            for (int i = 0; i < ossUrlList.length; i++) {
-                String ossUrl = ossUrlList[i];
-                String[] tmpOssUrl = ossUrl.split("/");
-                String likeOssUrl = tmpOssUrl[tmpOssUrl.length-1];
 
+            HashMap<String,String> mapUrl= new HashMap<>();
+            mapUrl.put("dd31ae2f-dd02-46b2-bfdb-eb721ea11066","/prod/fxy/android/detection/20240923/d3e5552e-344c-4c74-be91-468cbb22f22c.JPEG");
+
+            // 使用entrySet()遍历
+            for (Map.Entry<String, String> entry : mapUrl.entrySet()) {
+                System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());
+
+                String realmId = entry.getKey();
+                String ossUrl = entry.getValue();
                 mRealm.beginTransaction();
                 RealmResults<AsyncUploadRealm> realmResults ;
 
                 RealmQuery<AsyncUploadRealm> queryRealm =  mRealm.where(AsyncUploadRealm.class)
-                        .like("ossUrl", "%"+likeOssUrl+"%")
-                        .or()
-                        .equalTo("ossUrl", ossUrl.replace("detection", "tally"))
-                        .or()
-                        .equalTo("ossUrl", ossUrl)
-                        .greaterThan("createTime",  timestamp)
-                        ;
+                        .equalTo("id",  realmId);
                 realmResults = queryRealm.sort("createTime").findAll();
-
-
                 for (AsyncUploadRealm item : realmResults) {
-                    item.setOssUrl(ossUrl);
+                    if (!ossUrl.isEmpty()){
+                        item.setOssUrl(ossUrl);
+                    }
                 }
                 realmResults.load();
                 mRealm.commitTransaction();
@@ -534,8 +465,8 @@ public class AsyncPictureUpload {
         }
         allowUpload = true;
     }
-    public void setIsAllRe(){
-        isAllRe = true;
+    public void setIsAllRePush(){
+        isAllRePush = true;
     }
 
     public void setStopUpload(){
@@ -580,13 +511,13 @@ public class AsyncPictureUpload {
         RealmQuery<AsyncUploadRealm> queryRealm =  mRealm.where(AsyncUploadRealm.class)
                 .in("isFinish",isFinish)
                 .equalTo("isDelete",0);
-        if (isAllRe){
+        if (isAllRePush){
             Integer[] pushStatus = {0,1};
             queryRealm.in("pushStatus",pushStatus)
 //                    .equalTo("notifyKey",fileKey)
 //                    .equalTo("uploadType",uploadType)
                     ;
-            isAllRe = false;
+            isAllRePush = false;
         }else{
             queryRealm.equalTo("pushStatus",0)
 //                    .equalTo("notifyKey",fileKey)

+ 9 - 3
app/src/main/java/com/fxy/common/OssService.java

@@ -26,6 +26,7 @@ import com.fxy.BuildConfig;
 import com.fxy.constant.SPCache;
 import com.fxy.net.Urls;
 import com.fxy.putIn.PutinPhotosMainActivity;
+import com.fxy.utils.UploadUtils;
 
 import org.json.JSONObject;
 
@@ -115,9 +116,9 @@ public class OssService {
         //OSSCredentialProvider credentialProvider = new OSSStsTokenCredentialProvider(accessKeyId, accessKeySecret, "");
 
         ClientConfiguration conf = new ClientConfiguration();
-        conf.setConnectionTimeout(120 * 1000); // 连接超时,默认15秒。
-        conf.setSocketTimeout(120 * 1000); // socket超时,默认15秒。
-        conf.setMaxConcurrentRequest(2); // 最大并发请求书,默认5个。
+        conf.setConnectionTimeout(240 * 1000); // 连接超时,默认15秒。
+        conf.setSocketTimeout(240 * 1000); // socket超时,默认15秒。
+        conf.setMaxConcurrentRequest(10); // 最大并发请求书,默认5个。
         conf.setMaxErrorRetry(3); // 失败后最大重试次数,默认2次。
         oss = new OSSClient(mContext, endpoint, credentialProvider, conf);
 
@@ -151,9 +152,13 @@ public class OssService {
             public void uncaughtException(Thread t, Throwable e) {
                 // 在这里处理线程抛出的异常,并使用传递的参数进行操作
                 XLog.e("oss上传出现异常",e.getMessage());
+                UploadUtils.delUploadTime(mContext);
             }
         });
         thread.start();
+        UploadUtils.setUploadTime(mContext);
+
+
 
         //new ossThread(filePath, uploadName , num,handler).start();
         // task.cancel(); // 可以取消任务
@@ -201,6 +206,7 @@ public class OssService {
 
             XLog.e("开始执行上传"+getFilePath()+objectKey+"上传的目录是:"+urlPath);
 
+
             // 设置进度回调
             put.setProgressCallback(new OSSProgressCallback<PutObjectRequest>() {
                 @Override

+ 1 - 1
app/src/main/java/com/fxy/common/UploadDialog.java

@@ -36,7 +36,7 @@ public class UploadDialog {
 
     private void initData(){
         asyncPictureUpload = new AsyncPictureUpload(Objects.requireNonNull(mActivity));
-        asyncPictureUpload.setIsAllRe();
+        asyncPictureUpload.setIsAllRePush();
         progressDialog = new ProgressDialog(mActivity);
         progressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
             @Override

+ 2 - 3
app/src/main/java/com/fxy/main/fragment/MineFragment.java

@@ -503,10 +503,9 @@ public class MineFragment extends BaseFragment {
 
             SPCache sp = SPCache.getInstance(getActivity());
             String newsFileName = RxTimeTool.getYestoryDate("MMddHHmmss")+fileName+"-"+sp.getUserName();
-            String path_prefix = sp.getResourcePrefix()+"/android/log/"+ RxTimeTool.getYestoryDate("yyyyMMdd")+"/";
 
-            FiledUpload filedUpload = new FiledUpload(getActivity(),"");
-            filedUpload.filedUpload(file.toString(),path_prefix+newsFileName);
+            FiledUpload filedUpload = new FiledUpload(getActivity(),"log");
+            filedUpload.filedUpload(file.toString(),newsFileName);
 
         }catch (Exception e){
             XLog.e("上传文件失败"+e.getMessage());

+ 13 - 3
app/src/main/java/com/fxy/service/UploadJobService.java

@@ -6,6 +6,7 @@ import android.content.Context;
 
 import com.elvishew.xlog.XLog;
 import com.fxy.base.UploadContentProvider;
+import com.fxy.baselibrary.language.other.CommSharedUtil;
 import com.fxy.common.AsyncFileUpload;
 
 public class UploadJobService  extends JobService {
@@ -25,13 +26,20 @@ public class UploadJobService  extends JobService {
         XLog.d("------------执行异步上传图片--------------------"+jobParameters.getJobId());
         asyncFileUpload = new AsyncFileUpload(context);
 
-        asyncFileUpload.setStartUpload();
-        int awaitNum = asyncFileUpload.getAllAwaitNum();
+
+        Integer[] pushStatus = {0,1};
+
+        int awaitNum = asyncFileUpload.getAllAwaitNum(pushStatus);
         if (awaitNum == 0){
             // 标记任务为已完成(如果你不需要重试)
             jobFinished(jobParameters, false);
+            return false;
+        }else{
+            asyncFileUpload.setStartUpload();
+            jobFinished(jobParameters, true);
+            return true;
         }
-        return false;
+
     }
 
     @Override
@@ -43,4 +51,6 @@ public class UploadJobService  extends JobService {
     }
 
 
+
+
 }

+ 4 - 4
app/src/main/java/com/fxy/utils/JobUtils.java

@@ -47,8 +47,8 @@ public class JobUtils {
 
         // 其他设置,如网络条件、延迟等
         builder.setMinimumLatency(1000 * 60 * leisure); // 延迟至少60秒
-//        builder.setMinimumLatency(1000); // 延迟至少60秒
-        builder.setOverrideDeadline(2*60 * 1000 * 60); // 最多延迟2小时
+//        builder.setMinimumLatency(10); // 延迟至少60秒
+        builder.setOverrideDeadline(4*60 * 1000 * 60); // 最多延迟2小时
 
         JobInfo jobInfo = builder.build();
 
@@ -87,8 +87,8 @@ public class JobUtils {
 
 
         // 其他设置,如网络条件、延迟等
-        builder.setMinimumLatency(1000 * 30); // 延迟至少60秒
-//        builder.setMinimumLatency(1000); // 延迟至少60秒
+        builder.setMinimumLatency(1000 * 90); // 延迟至少60秒
+        //builder.setMinimumLatency(1000); // 延迟至少60秒
         builder.setOverrideDeadline(2*60 * 1000 * 60); // 最多延迟2分钟
 
         JobInfo jobInfo = builder.build();

+ 55 - 1
app/src/main/java/com/fxy/utils/UploadUtils.java

@@ -1,12 +1,18 @@
 package com.fxy.utils;
 
+import android.content.Context;
+
+import com.fxy.baselibrary.language.other.CommSharedUtil;
 import com.fxy.realm.AsyncUploadRealm;
 
+import java.util.Calendar;
+
 import io.realm.Realm;
 import io.realm.RealmResults;
 
 public class UploadUtils {
-    public static int getAwaitNum(Realm mRealm,String uploadType){
+    public static String currentUploadTimeTag="oss_current_upload_time";
+     public static int getAwaitNum(Realm mRealm,String uploadType){
         RealmResults<AsyncUploadRealm> realmResults  = mRealm.where(AsyncUploadRealm.class)
                 .equalTo("isDelete",0)
                 .equalTo("pushStatus",0)
@@ -24,4 +30,52 @@ public class UploadUtils {
         realmResults.load();
         return  realmResults.size();
     }
+    public static long getCurrentTime(){
+        Calendar calendar = Calendar.getInstance();
+        return calendar.getTimeInMillis();
+    }
+
+    /**
+     * 计算两个时间戳之间的差异,并返回以秒为单位的结果。
+     *
+     * @param timestamp1 第一个时间戳(毫秒)
+     * @param timestamp2 第二个时间戳(毫秒)
+     * @return 差异的秒数
+     */
+    public static long calculateDifferenceInSeconds(long timestamp1, long timestamp2) {
+        // 计算两个时间戳之间的差异(毫秒)
+        long differenceInMillis = Math.abs(timestamp1 - timestamp2);
+
+        // 将差异转换为秒
+        return differenceInMillis / 1000;
+    }
+
+    public static boolean getUploadExists(Context context){
+       String  currentUploadTimeStr = CommSharedUtil.getInstance(context).getString(currentUploadTimeTag,"");
+
+       if (currentUploadTimeStr.isEmpty()){
+           return true;
+       }
+        long diff = calculateDifferenceInSeconds( getCurrentTime() , Long.getLong(currentUploadTimeStr));
+        return diff >= 60 * 5;
+    }
+
+    /**
+     * 设置上传时间
+     * @param context Context
+     */
+    public static void setUploadTime(Context context){
+        CommSharedUtil.getInstance(context).putString(currentUploadTimeTag,String.valueOf(getCurrentTime()));
+    }
+
+    /**
+     * 删除上传时间
+     * @param context Context
+     * @return boolean
+     */
+    public static boolean delUploadTime(Context context){
+        CommSharedUtil.getInstance(context).remove(currentUploadTimeTag);
+        return true;
+    }
+
 }