package safeluck.drive.evaluation.worker
|
|
import android.content.Context
|
import android.text.TextUtils
|
import androidx.work.Worker
|
import androidx.work.WorkerParameters
|
import com.anyun.exam.lib.MyLog
|
import com.google.gson.Gson
|
import com.google.gson.JsonParser
|
import safeluck.drive.evaluation.Constant
|
import safeluck.drive.evaluation.DB.WorkRoomDataBase
|
import safeluck.drive.evaluation.DB.failitems.FailedProj
|
import safeluck.drive.evaluation.DB.failitems.LuKaoFailedProj
|
import safeluck.drive.evaluation.bean.ExamPlatformData
|
import safeluck.drive.evaluation.im.MessageProcessor
|
import safeluck.drive.evaluation.platformMessage.JKMessage0203
|
|
/**
|
* 一收到远程服务给的评判消息
|
* 实现插入科二、科三失败项目表
|
* 播放tts
|
* 发送0203评判消息给服务器
|
*/
|
class TTSWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
|
var gson:Gson =Gson()
|
override fun doWork(): Result {
|
val jkMessage0203 = JKMessage0203()
|
jkMessage0203.phone = ExamPlatformData.getInstance().phone
|
jkMessage0203.ID = ExamPlatformData.getInstance().id
|
jkMessage0203.exam_id = ExamPlatformData.getInstance().exam_id
|
var ttsInput = inputData.getString(Constant.TTS);
|
|
|
val jsonArray = JsonParser.parseString(ttsInput).asJsonArray
|
|
for ( i in 0 until jsonArray.size()) {
|
val jsonObject = jsonArray[i].asJsonObject
|
val emp_id = jsonObject["wrong_id"].asInt
|
|
var utc = jsonObject["utc"].asString
|
MyLog.i("评判消息解析之前的utc=$utc")
|
MyLog.i("wrong_id=$emp_id")
|
utc = utc.substring(2, utc.length - 3)
|
MyLog.i("评判消息解析之后的utc=$utc")
|
val sn = jsonObject["sn"].asInt
|
|
if (emp_id>1000){
|
var ttsStr=WorkRoomDataBase.getWorkRoomDataBase(applicationContext).criteriaIIIDao.queryItemForCriteriaIIINoLive(emp_id-1000)
|
ExamPlatformData.getInstance().tts.speak(ttsStr.getDeducting_reason() + if (ttsStr.getScore_deducting() == 100) "不合格" else "扣" +
|
ttsStr.getScore_deducting() + "分")
|
jkMessage0203.fail_item_id = ttsStr.item_id
|
jkMessage0203.fail_score = ttsStr.score_deducting
|
jkMessage0203.fail_reason = ttsStr.deducting_reason
|
}else{
|
var ttsStr=WorkRoomDataBase.getWorkRoomDataBase(applicationContext).criteriaIDao.queryItemForCriteriaINoLive(emp_id)
|
ExamPlatformData.getInstance().tts.speak(ttsStr.getDeducting_reason() + if (ttsStr.getScore_deducting() == 100) "不合格" else "扣" +
|
ttsStr.getScore_deducting() + "分")
|
jkMessage0203.fail_item_id =ttsStr.item_id
|
jkMessage0203.fail_score = ttsStr.score_deducting
|
jkMessage0203.fail_reason = ttsStr.deducting_reason
|
}
|
|
|
if (!TextUtils.isEmpty(utc) && utc.length > 12) {
|
utc = utc.substring(0, 12)
|
}
|
jkMessage0203.timeBCD = utc
|
|
|
MessageProcessor.getInstance().sendMessage(jkMessage0203)
|
|
|
|
if (emp_id<1000) { //场地评判消息
|
if (emp_id > 31 || emp_id < 0) {
|
MyLog.i("emp_id超出范围不能插入数据库(I类考场)")
|
|
}else{
|
val failedProj = FailedProj(Constant.SUBJECT_I, emp_id, Constant.TEST_STU_ID, utc, sn)
|
MyLog.i("插入fail_projects表=$failedProj")
|
WorkRoomDataBase.getWorkRoomDataBase(applicationContext).failProjDao.insert(failedProj)
|
}
|
|
}
|
if (emp_id>1000) { //道路 评判消息
|
|
if (emp_id >1066 || emp_id < 1000) {
|
MyLog.i("emp_id超出范围不能插入数据库(路考类考场)")
|
}else{
|
val failedProj = LuKaoFailedProj(Constant.SUBJECT_III, (emp_id-1000), Constant.TEST_STU_ID, utc, sn)
|
MyLog.i("插入路考fail_projects表=$failedProj")
|
WorkRoomDataBase.getWorkRoomDataBase(applicationContext).luKaoFailProjDao.insert(failedProj)
|
}
|
|
}
|
|
|
}
|
|
|
return Result.success()
|
}
|
}
|