解决播放日志重复上传问题

This commit is contained in:
刘金华 2023-10-17 18:12:23 +08:00
parent c8cf8d6b37
commit 8cbb511dd6
21 changed files with 215 additions and 126 deletions

File diff suppressed because one or more lines are too long

View File

@ -21,8 +21,8 @@ android {
applicationId "net.sysolution.taxiapp" applicationId "net.sysolution.taxiapp"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 237 versionCode 238
versionName "3.3.3-beta26.3.9.3.94-release" versionName "3.3.3-beta26.3.9.3.95-release"
//alphaxx - ,bug //alphaxx - ,bug
//Betaxx - //Betaxx -
@ -55,6 +55,7 @@ android {
26.3.8.3 taxiApp刷新列表时广,广regions也加入缓存机制 26.3.8.3 taxiApp刷新列表时广,广regions也加入缓存机制
26.3.8.6.9 38s 26.3.8.6.9 38s
26.3.9 webSocket的连接保活代码gps坐标记录两个点的距离由原来的50米记录一次改为20米记录一次 26.3.9 webSocket的连接保活代码gps坐标记录两个点的距离由原来的50米记录一次改为20米记录一次
3.3.3-beta26.3.9.3.94 gps开关查询广
**/ **/
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@ -64,8 +64,10 @@ class TaxiApp:Application() {
var timedAds:ArrayList<Advertise> = ArrayList() var timedAds:ArrayList<Advertise> = ArrayList()
var activity:PlayActivity? = null var activity:PlayActivity? = null
//日志定时器 //gps日志定时器
var gpsTimer: KuroTimer? = null var gpsTimer: Timer? = null
//播放日志定时器
var playerLogTimer: Timer? = null
var testCount = 0 var testCount = 0
val TAG = "TaxiApp" val TAG = "TaxiApp"

View File

@ -0,0 +1,18 @@
package cn.trans88.taxiappkotlin.logic.model;
/**
* @Author LJH
* @Time 2023/10/11
* @description
*/
public class LoggerState extends SanleResponse{
private Boolean turn_on = false;
public Boolean getTurn_on() {
return turn_on;
}
public void setTurn_on(Boolean turn_on) {
this.turn_on = turn_on;
}
}

View File

@ -38,6 +38,7 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.util.*
import java.util.concurrent.ThreadPoolExecutor import java.util.concurrent.ThreadPoolExecutor
/** /**
@ -430,20 +431,13 @@ object ConnManger {
YoungUtil.YoungLog("sendLocation in MainThread is ${Looper.getMainLooper().thread === Thread.currentThread()}") YoungUtil.YoungLog("sendLocation in MainThread is ${Looper.getMainLooper().thread === Thread.currentThread()}")
//如果这里突然有大量的信息序列化是不是同样会内存溢出 //如果这里突然有大量的信息序列化是不是同样会内存溢出
val locations = DaoUtil.getLocations() val locations = DaoUtil.getLocations()
//edit by ljh @2023/8/8 每次只查20条定点数据防止数据量大导致内存爆满
// val locations = DaoUtil.getLocationDao().queryBuilder().limit(20).list()
if (locations.isNotEmpty()) { if (locations.isNotEmpty()) {
// val requestJson: String = if (locations.size < 20) {
// ProcessingCommands.gson.toJson(locations)
// } else {
// ProcessingCommands.gson.toJson(locations.subList(0, 19))
// }
val requestJson: String = ProcessingCommands.gson.toJson(locations) val requestJson: String = ProcessingCommands.gson.toJson(locations)
//edit by ljh @2023/10/12
//日志存卡里 for (location in locations) {
// taxiApp.saveLog("上传的坐标信息:$requestJson") DaoUtil.getLocationDao().delete(location)
}
val parse = ("application/json;charset=UTF-8").toMediaTypeOrNull() val parse = ("application/json;charset=UTF-8").toMediaTypeOrNull()
val body = RequestBody.create(parse, requestJson) val body = RequestBody.create(parse, requestJson)
@ -468,21 +462,14 @@ object ConnManger {
override fun onResponse(call: Call, response: Response) { override fun onResponse(call: Call, response: Response) {
YoungUtil.YoungLog("上传坐标成功:${response.message},response is Sussceful ${response.isSuccessful}${response.code}") YoungUtil.YoungLog("上传坐标成功:${response.message},response is Sussceful ${response.isSuccessful}${response.code}")
if (response.code == 200) { //日志存卡里
// for (location in locations) { // "日志存卡里:$requestJson".logd()
// DaoUtil.getLocationDao().delete(location) // taxiApp.saveLog(requestJson)
// } // if (response.code == 200) {
// if (locations.size < 20) { // DaoUtil.getLocationDao().deleteAll()
// DaoUtil.getLocationDao().deleteAll() // //日志存卡里
// } else { //// taxiApp.saveLog("上传坐标成功,删除上传成功的坐标:${locations.toString()}")
// for (index in 0..19) { // }
// DaoUtil.getLocationDao().delete(locations[index])
// }
// }
DaoUtil.getLocationDao().deleteAll()
//日志存卡里
// taxiApp.saveLog("上传坐标成功,删除上传成功的坐标:${locations.toString()}")
}
} }
}) })
@ -493,31 +480,31 @@ object ConnManger {
* 发送坐标 * 发送坐标
*/ */
fun sendLocation() { fun sendLocation() {
taxiApp.gpsTimer?.let {
it.cancel()
it.purge()
}
synchronized(ConnManger::class.java){ synchronized(ConnManger::class.java){
taxiApp.gpsTimer?.let {
it.cancel()
it.purge()
}
//edit by yzd @20211201 //edit by yzd @20211201
//if (Settings.gpsSwitch) { //if (Settings.gpsSwitch) {
if (Configurations.config(TaxiApp.instance()).gpsSwitch()) { if (Configurations.config(TaxiApp.instance()).gpsSwitch()) {
"gpsSwitch on".loge() "gpsSwitch on".loge()
taxiApp.gpsTimer = KuroTimer() taxiApp.gpsTimer = Timer()
taxiApp.gpsTimer?.schedule(object : KuroTimerTask() { taxiApp.gpsTimer?.schedule(object : TimerTask() {
override fun run() { override fun run() {
sendLocationToWeb() sendLocationToWeb()
// sendLocation() // sendLocation()
} }
}, 0,10000) }, 5000,10000)
} else { } else {
"gpsSwitch off".loge() "gpsSwitch off".loge()
taxiApp.gpsTimer = KuroTimer() taxiApp.gpsTimer = Timer()
taxiApp.gpsTimer?.schedule(object : KuroTimerTask() { taxiApp.gpsTimer?.schedule(object : TimerTask() {
override fun run() { override fun run() {
sendLocationToWeb() sendLocationToWeb()
// sendLocation() // sendLocation()
} }
}, 0,60 * 60 * 1000) }, 5000,60 * 60 * 1000)
} }
} }
} }
@ -642,75 +629,70 @@ object ConnManger {
} }
var loggerTimer:KuroTimer? = null var loggerTimer:KuroTimer? = null
/**
* 上传播放日志
*/
fun sendLoggerToWeb(){
YoungUtil.YoungLog("sendLogger in Thread is ${Looper.getMainLooper().thread === Thread.currentThread()}")
val playLoggers = DaoUtil.getPlayLoggers()
if (playLoggers.isNotEmpty()) {
//#edit by ljh @2023/6/5 改成大批量看是否能减小流量消耗
val requestJson = ProcessingCommands.gson.toJson(playLoggers)
for (playLogger in playLoggers) {
DaoUtil.getPlayLogger().delete(playLogger)
}
val okHttpClient = OkHttpClient()
YoungUtil.YoungLog("准备上传日志")
val parse = ("application/json;charset=UTF-8").toMediaTypeOrNull()
val body = RequestBody.create(parse, requestJson)
YoungUtil.YoungLog("sendLogger:${requestJson}")
val request: Request = Request.Builder()
.url(Configurations.config(TaxiApp.instance()).logServiceUrl() + "postPlayerLog") //要访问的链接
.addHeader("Authorization", "Bearer ${Configurations.config(TaxiApp.instance()).appToken()}")
.addHeader("Accept-Encoding", "gzip")
.post(body)
.build()
val call = okHttpClient.newCall(request)
call.enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
YoungUtil.YoungLog("上传日志失败:${e.message}")
}
override fun onResponse(call: Call, response: Response) {
YoungUtil.YoungLog("上传日志成功:${response.message},response isSuccessful ${response.isSuccessful}${response.code}")
// if (response.code == 200) {
// //#edit by ljh @2023/6/5 删除批量上传的日志
// DaoUtil.getPlayLogger().deleteAll()
// }
"删除已上传的日志".logd()
}
})
}
}
/** /**
* 发送播放日志 * 发送播放日志
*/ */
fun sendLogger() { fun sendLogger() {
taxiApp.playerLogTimer?.let {
it.cancel()
it.purge()
}
//edit by yzd @20211201 //edit by yzd @20211201
//if (Settings.loggerSwitch) { //if (Settings.loggerSwitch) {
if (Configurations.config(TaxiApp.instance()).loggerSwitch()) { if (Configurations.config(TaxiApp.instance()).loggerSwitch()) {
YoungUtil.YoungLog("sendLogger in Thread is ${Looper.getMainLooper().thread === Thread.currentThread()}") taxiApp.playerLogTimer = Timer()
val playLoggers = DaoUtil.getPlayLoggers() taxiApp.playerLogTimer?.schedule(object :TimerTask(){
if (playLoggers.isNotEmpty()) {
val requestJson: String = if (playLoggers.size < 20) {
ProcessingCommands.gson.toJson(playLoggers)
} else {
// ProcessingCommands.gson.toJson(playLoggers.subList(0, 19))
//#edit by ljh @2023/6/5 改成大批量看是否能减小流量消耗
ProcessingCommands.gson.toJson(playLoggers)
}
"requestJson:$requestJson".loge()
val okHttpClient = OkHttpClient()
YoungUtil.YoungLog("准备上传日志")
val parse = ("application/json;charset=UTF-8").toMediaTypeOrNull()
val body = RequestBody.create(parse, requestJson)
YoungUtil.YoungLog("sendLogger:${requestJson}")
val request: Request = Request.Builder()
.url(Configurations.config(TaxiApp.instance()).logServiceUrl() + "postPlayerLog") //要访问的链接
.addHeader("Authorization", "Bearer ${Configurations.config(TaxiApp.instance()).appToken()}")
.addHeader("Accept-Encoding", "gzip")
.post(body)
.build()
val call = okHttpClient.newCall(request)
call.enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
YoungUtil.YoungLog("上传日志失败:${e.message}")
}
override fun onResponse(call: Call, response: Response) {
YoungUtil.YoungLog("上传日志成功:${response.message},response isSuccessful ${response.isSuccessful}${response.code}")
// if (response.code == 200) {
// if (playLoggers.size < 20) {
// DaoUtil.getPlayLogger().deleteAll()
// } else {
//// for (index in 0..19) {
//// DaoUtil.getPlayLogger().delete(playLoggers[index])
//// }
//
// }
// }
if (response.code == 200) {
//#edit by ljh @2023/2/21
// playLoggers.forEach{
// DaoUtil.getPlayLogger().delete(it)
// }
//#edit by ljh @2023/6/5 删除批量上传的日志
DaoUtil.getPlayLogger().deleteAll()
}
"删除已上传的日志".logd()
}
})
}
loggerTimer = KuroTimer()
loggerTimer?.schedule(object : KuroTimerTask() {
override fun run() { override fun run() {
"loggerTimer task started".logd() sendLoggerToWeb()
sendLogger()
} }
}, 30000) },5000,30000)
} }
} }

View File

@ -82,6 +82,12 @@ object ProcessingCommands {
"get_advertise_order" -> sendOrderInfo(task,baseTask.type) "get_advertise_order" -> sendOrderInfo(task,baseTask.type)
"update_player_log_switch" -> playLoggerSwitch(task,baseTask.type) "update_player_log_switch" -> playLoggerSwitch(task,baseTask.type)
"update_gps_log_switch" -> gpsSwitch(task,baseTask.type) "update_gps_log_switch" -> gpsSwitch(task,baseTask.type)
//获取播放日志开关状态
"get_player_log_state" -> getLoggerSwitch(task,baseTask.type)
//获取gps日志开关状态
"get_gps_state" -> getGpsSwitch(task,baseTask.type)
//直接清空所有广告
"clear_ads" -> clearAdvertises(task,baseTask.type)
"get_log_file_list" -> getLogFilesAllName(task,baseTask.type) "get_log_file_list" -> getLogFilesAllName(task,baseTask.type)
"beat_reply" -> beatCheck(task,baseTask.type) "beat_reply" -> beatCheck(task,baseTask.type)
else -> YoungUtil.YoungLog("三乐 未知命令") else -> YoungUtil.YoungLog("三乐 未知命令")
@ -99,24 +105,13 @@ object ProcessingCommands {
val baseResponse = gson.fromJson<BaseResponse>(task) val baseResponse = gson.fromJson<BaseResponse>(task)
val gpsSwitch = gson.fromJson<Switch>(task) val gpsSwitch = gson.fromJson<Switch>(task)
//__need delete sss
//Configurations.config(TaxiApp.instance()).enableWriteLogSave(true)
//LogUtil.setLogWriteEnable(true)
//__need delete eee
//edit by yzd @20211201 //edit by yzd @20211201
//Settings.gpsSwitch =gpsSwitch.isTurn_on //Settings.gpsSwitch =gpsSwitch.isTurn_on
Configurations.config(TaxiApp.instance()).gpsSwitchSave(gpsSwitch.isTurn_on) Configurations.config(TaxiApp.instance()).gpsSwitchSave(gpsSwitch.isTurn_on)
if (gpsSwitch.isTurn_on){ ConnManger.sendLocation()
//edit by ljh @2023/9/7 // if (gpsSwitch.isTurn_on){
// ConnManger.gpsTimer?.cancel() // ConnManger.sendLocation()
// ConnManger.gpsTimer?.purge() // }
ConnManger.sendLocation()
}
baseResponse.type = type baseResponse.type = type
val response = gson.toJson(baseResponse) val response = gson.toJson(baseResponse)
@ -165,6 +160,41 @@ object ProcessingCommands {
// val playAdvertiseList = Repository.getTestPlayCircularList() // val playAdvertiseList = Repository.getTestPlayCircularList()
// } // }
/**
* 获取播放日志开关状态
*/
private fun getLoggerSwitch(task: String, type: String) {
val baseResponse = gson.fromJson<BaseResponse>(task)
val sanleResponse = LoggerState()
val turn_on = Configurations.config(TaxiApp.instance()).loggerSwitch()
"getLoggerSwitch-->当前播放日志开关状态:$turn_on".logd()
sanleResponse.type = type
sanleResponse.id = baseResponse.id
sanleResponse.task_id = baseResponse.task_id
sanleResponse.turn_on = turn_on
val response = gson.toJson(sanleResponse)
send(response)
}
/**
* 获取Gps日志开关状态
*/
private fun getGpsSwitch(task: String, type: String) {
val baseResponse = gson.fromJson<BaseResponse>(task)
val sanleResponse = LoggerState()
val turn_on = Configurations.config(TaxiApp.instance()).gpsSwitch()
"getGpsSwitch-->当前gps日志开关状态$turn_on".logd()
sanleResponse.type = type
sanleResponse.id = baseResponse.id
sanleResponse.task_id = baseResponse.task_id
sanleResponse.turn_on = turn_on
val response = gson.toJson(sanleResponse)
send(response)
}
/** /**
* 设置是否上传播放日志 * 设置是否上传播放日志
*/ */
@ -175,8 +205,8 @@ object ProcessingCommands {
//Settings.loggerSwitch =loggerSwitch.isTurn_on //Settings.loggerSwitch =loggerSwitch.isTurn_on
Configurations.config(TaxiApp.instance()).loggerSwitchSave(loggerSwitch.isTurn_on) Configurations.config(TaxiApp.instance()).loggerSwitchSave(loggerSwitch.isTurn_on)
if (loggerSwitch.isTurn_on){ if (loggerSwitch.isTurn_on){
ConnManger.loggerTimer?.cancel() // ConnManger.loggerTimer?.cancel()
ConnManger.loggerTimer?.purge() // ConnManger.loggerTimer?.purge()
ConnManger.sendLogger() ConnManger.sendLogger()
} }
@ -543,6 +573,40 @@ object ProcessingCommands {
send(response) send(response)
} }
/**
* 清空所有广告
*/
private fun clearAds() {
DaoUtil.deleteAllAdvertise()
DaoUtil.getSanleAdvertise().deleteAll()
DaoUtil.getPositionAdvertise().deleteAll()
DaoUtil.getContainerDao().deleteAll()
DaoUtil.getRegion().deleteAll()
DaoUtil.getTimeSpan().deleteAll()
//edit by ljh @2023/8/14
taxiApp.daoAds.clear()
taxiApp.regionsList.clear()
"所有广告都清空了".logd()
try {
RefreshPlayer.refresh()
} catch (e: InterruptedException) {
e.printStackTrace()
}
}
/**
* 清空所有广告的指令
* @param task String
* @param type String
*/
private fun clearAdvertises(task: String, type: String) {
val baseResponse = gson.fromJson<BaseResponse>(task)
clearAds()
baseResponse.type = type
val response = gson.toJson(baseResponse)
send(response)
}
/** /**
* 三乐转换账号 * 三乐转换账号
*/ */

View File

@ -32,6 +32,7 @@ import cn.trans88.taxiappkotlin.logic.dao.DaoUtil
import cn.trans88.taxiappkotlin.logic.dao.PlayLoggerDao import cn.trans88.taxiappkotlin.logic.dao.PlayLoggerDao
import cn.trans88.taxiappkotlin.logic.gps.GpsReceiver import cn.trans88.taxiappkotlin.logic.gps.GpsReceiver
import cn.trans88.taxiappkotlin.logic.model.Advertise import cn.trans88.taxiappkotlin.logic.model.Advertise
import cn.trans88.taxiappkotlin.logic.model.Location
import cn.trans88.taxiappkotlin.logic.network.* import cn.trans88.taxiappkotlin.logic.network.*
import cn.trans88.taxiappkotlin.play.RefreshPlayer import cn.trans88.taxiappkotlin.play.RefreshPlayer
import cn.trans88.taxiappkotlin.ui.advertise.AdvertiseType import cn.trans88.taxiappkotlin.ui.advertise.AdvertiseType
@ -90,7 +91,6 @@ class PlayActivity : AppCompatActivity(), NetworkCallback, BusCallback, OnScreen
setFlagHide() setFlagHide()
} }
//测试 //测试
// Advertise().toString().loge() // Advertise().toString().loge()
@ -107,10 +107,9 @@ class PlayActivity : AppCompatActivity(), NetworkCallback, BusCallback, OnScreen
// } // }
taxiApp.activity = this taxiApp.activity = this
val isFirstInstalled = Configurations.config(this).isFirstInstalled val isFirstInstalled = Configurations.config(this).isFirstInstalled
if (isFirstInstalled){ if (isFirstInstalled){
//升级后打开日志 //升级后关闭日志
Configurations.config(this).gpsSwitchSave(false) Configurations.config(this).gpsSwitchSave(false)
Configurations.config(this).loggerSwitchSave(false) Configurations.config(this).loggerSwitchSave(false)
Configurations.config(this).isFirstInstalledSave(false) Configurations.config(this).isFirstInstalledSave(false)
@ -178,6 +177,7 @@ class PlayActivity : AppCompatActivity(), NetworkCallback, BusCallback, OnScreen
mLocationManager?.removeUpdates(getLocationListener()) mLocationManager?.removeUpdates(getLocationListener())
} }
},30 * 1000) },30 * 1000)
// testLocation()
} }
//#edit by ljh 2023/2/16 //#edit by ljh 2023/2/16
@ -185,6 +185,28 @@ class PlayActivity : AppCompatActivity(), NetworkCallback, BusCallback, OnScreen
return playViewModel return playViewModel
} }
var testcount = 60
fun testLocation(){
Timer().schedule(object : TimerTask(){
override fun run() {
testcount--
if (testcount>=0){
val location = Location().apply {
timestamp = System.currentTimeMillis()
setLongitude(1.0)
setLatitude(1.0)
setBearing(1F)
setSpeed(testcount.toFloat())
distance = 10f
elapse = testcount.toLong()
}
DaoUtil.getLocationDao().insert(location)
"存储了假数据testcount:$testcount,${location.toString()}".logd()
}
}
},0,5000)
}
private fun bindConnService() { private fun bindConnService() {
val intent = Intent() val intent = Intent()
intent.setPackage("com.xixun.xy.conn") intent.setPackage("com.xixun.xy.conn")

View File

@ -477,7 +477,6 @@ class PlayViewModel(val lifecycle: Lifecycle, private val fl_play: FrameLayout,
"日志durarion:${curLogger!!.duration}".loge() "日志durarion:${curLogger!!.duration}".loge()
} }
val createView = fl_play.createView(fl_play.context, advertise, 0) val createView = fl_play.createView(fl_play.context, advertise, 0)
// fl_play.children.iterator().forEach { // fl_play.children.iterator().forEach {
@ -799,7 +798,7 @@ class PlayViewModel(val lifecycle: Lifecycle, private val fl_play: FrameLayout,
curLogger!!.duration = roundingDuration.toLong() curLogger!!.duration = roundingDuration.toLong()
DaoUtil.getPlayLoggerDao().insert(curLogger) DaoUtil.getPlayLoggerDao().insert(curLogger)
"存储日志:${curLogger?.media_url}".loge() "存储日志:${curLogger?.begin_play_ts}".loge()
} }
curLogger = null curLogger = null
} }
@ -841,7 +840,8 @@ class PlayViewModel(val lifecycle: Lifecycle, private val fl_play: FrameLayout,
duration = advertise.duration.toLong() duration = advertise.duration.toLong()
} }
} }
YoungUtil.YoungLog("初始化curLogger" + curLogger)
YoungUtil.YoungLog("初始化curLogger$curLogger")
} else { } else {
YoungUtil.YoungLog("初始化curLogger不等于空") YoungUtil.YoungLog("初始化curLogger不等于空")
} }

View File

@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":238,"versionName":"3.3.3-beta26.3.94location-debug","enabled":true,"outputFile":"TaxiApp_v3.3.3-beta26.3.94location-debug{238}.apk","fullName":"debug","baseName":"debug","dirName":""},"path":"TaxiApp_v3.3.3-beta26.3.94location-debug{238}.apk","properties":{}}] [{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":237,"versionName":"3.3.3-beta26.3.9.3.94-debug","enabled":true,"outputFile":"TaxiApp_v3.3.3-beta26.3.9.3.94-debug{237}.apk","fullName":"debug","baseName":"debug","dirName":""},"path":"TaxiApp_v3.3.3-beta26.3.9.3.94-debug{237}.apk","properties":{}}]

View File

@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":236,"versionName":"3.3.3-beta26.3.9.3.93-release","enabled":true,"outputFile":"TaxiApp_v3.3.3-beta26.3.9.3.93-release{236}.apk","fullName":"release","baseName":"release","dirName":""},"path":"TaxiApp_v3.3.3-beta26.3.9.3.93-release{236}.apk","properties":{}}] [{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":238,"versionName":"3.3.3-beta26.3.9.3.95-release","enabled":true,"outputFile":"TaxiApp_v3.3.3-beta26.3.9.3.95-release{238}.apk","fullName":"release","baseName":"release","dirName":""},"path":"TaxiApp_v3.3.3-beta26.3.9.3.95-release{238}.apk","properties":{}}]