| 26 | import java.util.regex.Pattern; |
| 27 | |
| 28 | public class GbFileHelper { |
| 29 | |
| 30 | private static String TAG = "GbFileHelper"; |
| 31 | |
| 32 | private static Context mContext; |
| 33 | private static String pPath; |
| 34 | |
| 35 | private static final DateTimeFormatter FORMATTER_DIGIT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").withLocale(Locale.US); |
| 36 | // 输出格式:2025-11-30T13:39:56 |
| 37 | private static final DateTimeFormatter FORMATTER_ISO = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss").withLocale(Locale.US); |
| 38 | |
| 39 | // 任务ID计数器 |
| 40 | private static int taskId = 0; |
| 41 | |
| 42 | // 存储 params -> taskId 的映射 |
| 43 | private static final Map<String, Integer> paramsToTaskIdMap = new HashMap<>(); |
| 44 | |
| 45 | // 存储 taskId -> RecordMp4 列表的映射 |
| 46 | private static final Map<Integer, List<Mp4Record>> taskIdToRecordFilesMap = new HashMap<>(); |
| 47 | |
| 48 | |
| 49 | public static void setContext(Context context) { |
| 50 | mContext = context; |
| 51 | } |
| 52 | |
| 53 | public static void setRecordPath(String path) { |
| 54 | pPath = path; |
| 55 | } |
| 56 | |
| 57 | // {StartTime:"2025-12-10T00:00:00",EndTime:"2025-12-10T23:59:59","cIndex":"0"} |
| 58 | public static int getTaskID(byte[] param) { |
| 59 | |
| 60 | if (param == null) { |
| 61 | Log.e(TAG, "getTaskID param is null"); |
| 62 | return -1; |
| 63 | } |
| 64 | String params = new String(param, StandardCharsets.UTF_8); |
| 65 | // 如果参数已存在,返回已有的taskId |
| 66 | Integer existingTaskId = paramsToTaskIdMap.get(params); |
| 67 | if (existingTaskId != null) { |
| 68 | return existingTaskId; |
| 69 | } |
| 70 | |
| 71 | // 生成新的taskId |
| 72 | int newTaskId = ++taskId; |
| 73 | |
| 74 | // 保存映射关系 |
| 75 | paramsToTaskIdMap.put(params, newTaskId); |
| 76 | |
| 77 | // 为新的taskId创建文件信息列表(根据params参数动态生成文件列表) |
| 78 | List<Mp4Record> fileList = getMp4RecordFiles(params); |
| 79 | taskIdToRecordFilesMap.put(newTaskId, fileList); |
| 80 | |
| 81 | return newTaskId; |
| 82 | } |
| 83 | |
| 84 | public static int getSumNum(int taskId) { |
| 85 | if (!taskIdToRecordFilesMap.containsKey(taskId)) { |
nothing calls this directly
no outgoing calls
no test coverage detected