[fea]
[核销、未通知小程序]
This commit is contained in:
yangyakun
2024-11-18 14:53:59 +08:00
parent d680db18a4
commit da414503b9
16 changed files with 1197 additions and 83 deletions

View File

@@ -4,30 +4,43 @@ import com.mogo.commons.storage.SharedPrefsMgr
import com.mogo.eagle.core.network.utils.digest.DigestUtils
import com.mogo.och.common.module.biz.login.LoginStatusManager
import com.mogo.och.weaknet.repository.db.bean.EventDataBean
import com.mogo.och.weaknet.repository.db.bean.WriteOffDataBean
/**
* 上报事件
*/
data class ShuttleEventRequest(val requestId: String, val sn: String, val businessType: Int,val eventList:MutableList<Event>){
companion object{
fun transformDb2Net(waitUpdateEvent: List<EventDataBean>): ShuttleEventRequest {
fun transformDb2Net(
waitUpdateEvent: List<EventDataBean>?,
waitUpdateWriteOffEvent: List<WriteOffDataBean>?
): ShuttleEventRequest {
val businessTypeShuttle = LoginStatusManager.getLoginInfo()?.businessType?:11
val md5Hex = DigestUtils.md5Hex(waitUpdateEvent.toString())
val eventList4Request = mutableListOf<Event>()
var tempEvent: Event?=null
waitUpdateEvent.forEach {
waitUpdateEvent?.forEach {
tempEvent = Event(it.eventType,
EventData(it.taskId,it.businessTime,it.writeVersion,it.siteId,it.seq,it.driverId,it.msgId)
)
eventList4Request.add(tempEvent!!)
}
waitUpdateWriteOffEvent?.forEach {
tempEvent = Event("WriteOff",
WriteOffEventData(it.msgId,it.taskId,it.siteId,it.driverId,it.orderNo,it.businessTime,it.businessTime)
)
eventList4Request.add(tempEvent!!)
}
val md5Hex = DigestUtils.md5Hex(eventList4Request.toString())
return ShuttleEventRequest(md5Hex, SharedPrefsMgr.getInstance().sn,
businessTypeShuttle,eventList4Request)
}
}
}
data class Event(var eventType: String?,val eventData: EventData)
data class Event(var eventType: String?,val eventData: EventDataBase)
open class EventDataBase(val msgtype:String)
data class EventData(
var taskId: Long?,
@@ -37,4 +50,14 @@ data class EventData(
var seq: Int?,
var driverId:Long?,
var msgId:String?
)
):EventDataBase(msgtype = "lineEvent")
data class WriteOffEventData(
var msgId: String?,
var taskId: Long?,
var siteId: Long?,
var driverId: Long?,
var orderNo: String?,
var businessTime: Long?,
var writeVersion: Long?,
):EventDataBase(msgtype = "writeoffEvent")

View File

@@ -9,39 +9,36 @@ import com.mogo.och.common.module.network.OchCommonServiceCallback
import com.mogo.och.weaknet.bean.request.ShuttleEventRequest
import com.mogo.och.weaknet.bean.WaitUploadLine
import com.mogo.och.weaknet.bean.WaitUploadTask
import com.mogo.och.weaknet.repository.net.project.dali.shuttle.DaliShuttleServiceManager
import com.mogo.och.weaknet.repository.db.bean.EventDataBean
import com.mogo.och.weaknet.repository.db.repository.EventDb
import com.mogo.och.weaknet.repository.RepositoryManager
import com.mogo.och.weaknet.repository.db.repository.SiteDb
import com.mogo.och.weaknet.repository.db.repository.WriteOffDb
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.BehaviorSubject
import java.util.concurrent.atomic.AtomicBoolean
object EventModel : EventDb.EventCallback {
object EventModel {
private val isUpdating by lazy { AtomicBoolean(false) }
private val createDefault = BehaviorSubject.createDefault(isUpdating.get())
fun load(){
if (RepositoryManager.supportDb()) {
EventDb.eventCallback = this
if (RepositoryManager.supportDb() || RepositoryManager.supportWriteOffDb()) {
BizLoopManager.postDelayed(loopUpdateInfo,2*60*1000)
}
}
fun release(){
if (RepositoryManager.supportDb()) {
EventDb.eventCallback = null
}
}
private val loopUpdateInfo = Runnable { updateEvent() }
override fun notifySyn() {
fun notifySyn() {
BizLoopManager.removeCallback(loopUpdateInfo)
updateEvent()
checkDbData()
@@ -62,8 +59,9 @@ object EventModel : EventDb.EventCallback {
isUpdating.set(true)
createDefault.onNext(isUpdating.get())
ThreadUtils.getSinglePool().submit {
val waitUpdateEvent = EventDb.queryWaitUpdateEvent()
if(waitUpdateEvent.isNullOrEmpty()){
val waitUpdateLineEvent = EventDb.queryWaitUpdateEvent()
val waitUpdateWriteOffEvent = WriteOffDb.queryWaitUpdateEvent()
if (waitUpdateLineEvent.isNullOrEmpty() && waitUpdateWriteOffEvent.isNullOrEmpty()) {
OchChainLogManager.writeChainLogDb("上报event","没有数据需要上报${Thread.currentThread().name}")
isUpdating.set(false)
createDefault.onNext(isUpdating.get())
@@ -71,15 +69,27 @@ object EventModel : EventDb.EventCallback {
return@submit
}
OchChainLogManager.writeChainLogDb("上报event","开始上报:${Thread.currentThread().name}")
val transformDb2Net = ShuttleEventRequest.transformDb2Net(waitUpdateEvent)
val transformDb2Net = ShuttleEventRequest.transformDb2Net(waitUpdateLineEvent,waitUpdateWriteOffEvent)
RepositoryManager.reportCabinEvent(AbsMogoApplication.getApp()!!,transformDb2Net,object :OchCommonServiceCallback<BaseData?>{
override fun onSuccess(data: BaseData?) {
waitUpdateEvent.forEach {
it.updateStatus = EventDataBean.updated
it.upDateTime = System.currentTimeMillis()
}
OchChainLogManager.writeChainLogDb("上报event成功","$transformDb2Net ${Thread.currentThread().name}")
EventDb.saveUpdateSuccess(waitUpdateEvent)
waitUpdateLineEvent?.let {lineEvents->
lineEvents.forEach {
it.updateStatus = EventDataBean.updated
it.upDateTime = System.currentTimeMillis()
}
EventDb.saveUpdateSuccess(lineEvents)
}
waitUpdateWriteOffEvent?.let {writeOffEvents->
writeOffEvents.forEach {
it.updateStatus = EventDataBean.updated
it.upDateTime = System.currentTimeMillis()
}
WriteOffDb.saveUpdateSuccess(writeOffEvents)
}
isUpdating.set(false)
createDefault.onNext(isUpdating.get())
val queryWaitUpdateEventCount = EventDb.queryWaitUpdateEventCount()

View File

@@ -126,12 +126,8 @@ object RepositoryManager {
return lineRepository?.endTask(taskId)
}
fun queryWriteoffCount(context: Context, taskId: Long, siteId: Long, callback: OchCommonServiceCallback<WriteOffCountResponse>?){
writeOffRepository?.queryWriteoffCount(context,taskId,siteId,callback)
}
fun haveRunningTask():Boolean{
return repository?.haveRunningTask()?:false
return lineRepository?.haveRunningTask()?:false
}
@@ -182,6 +178,10 @@ object RepositoryManager {
}
}
fun queryWriteoffCount(context: Context, taskId: Long, siteId: Long, callback: OchCommonServiceCallback<WriteOffCountResponse>?){
writeOffRepository?.queryWriteoffCount(context,taskId,siteId,callback)
}
fun writeOff(writeOffDetialMsg: WriteOffDetialMsg): Observable<PassengerWriteOffResponse.Result>? {
return writeOffRepository?.writeOffEvent(writeOffDetialMsg)
}

View File

@@ -19,19 +19,21 @@ import com.mogo.och.weaknet.repository.db.bean.LineDataBean
import com.mogo.och.weaknet.repository.db.bean.SiteDataBean
import com.mogo.och.weaknet.repository.db.bean.TaskDataBean
import com.mogo.och.weaknet.repository.db.bean.TaskSiteDataBean
import com.mogo.och.weaknet.repository.db.bean.WriteOffDataBean
import com.mogo.och.weaknet.repository.db.dao.ContrailDataDao
import com.mogo.och.weaknet.repository.db.dao.EventDataDao
import com.mogo.och.weaknet.repository.db.dao.LineDataDao
import com.mogo.och.weaknet.repository.db.dao.SiteDataDao
import com.mogo.och.weaknet.repository.db.dao.TaskDataDao
import com.mogo.och.weaknet.repository.db.dao.TaskSiteDataDao
import com.mogo.och.weaknet.repository.db.dao.WriteOffDataDao
import java.io.File
//注解Database告诉系统这是Room数据库对象
//entities指定该数据库有哪些表多张表就逗号分隔
//version指定数据库版本号升级时需要用到
//数据库继承自RoomDatabase
@Database(entities = [ContrailDataBean::class, LineDataBean::class, SiteDataBean::class, TaskDataBean::class, TaskSiteDataBean::class, EventDataBean::class], version = 4)
@Database(entities = [ContrailDataBean::class, LineDataBean::class, SiteDataBean::class, TaskDataBean::class, TaskSiteDataBean::class, EventDataBean::class, WriteOffDataBean::class], version = 5)
abstract class MyDataBase : RoomDatabase() {
override fun getOpenHelper(): SupportSQLiteOpenHelper {
@@ -58,8 +60,33 @@ abstract class MyDataBase : RoomDatabase() {
abstract val siteDataDao: SiteDataDao?
abstract val taskDataDao: TaskDataDao?
abstract val taskSiteDataDao: TaskSiteDataDao?
abstract val writeOffDataDao: WriteOffDataDao?
companion object {
private val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE ${EventDataBean.evnetDataTable} ADD COLUMN driver_id INTEGER");
}
}
private val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE ${SiteDataBean.siteDataTable} ADD COLUMN videoList TEXT");
database.execSQL("ALTER TABLE ${TaskSiteDataBean.usedTaskDataTable} ADD COLUMN videoList TEXT");
}
}
private val MIGRATION_3_4 = object : Migration(3, 4) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE ${EventDataBean.evnetDataTable} ADD COLUMN msg_id TEXT")
database.execSQL("ALTER TABLE ${EventDataBean.evnetDataTable} ADD COLUMN update_time INTEGER")
}
}
private val MIGRATION_4_5 = object : Migration(4, 5) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS `${WriteOffDataBean.writeoffDataTable}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `msg_id` TEXT, `expiry_time` INTEGER, `booking_time` INTEGER, `type` INTEGER, `task_id` INTEGER, `line_id` INTEGER, `site_id` INTEGER, `driver_id` INTEGER, `remaining_times` INTEGER, `order_no` TEXT, `uid` TEXT, `seq` TEXT, `business_time` INTEGER, `tick_size` INTEGER, `tick_name` TEXT, `event_save_time` INTEGER NOT NULL, `update_status` INTEGER NOT NULL, `update_time` INTEGER)")
}
}
fun getDBName():MyDataBase{
val roomName = when (ProjectUtils.getProjectType()) {
Project.SAAS -> {
@@ -88,11 +115,10 @@ abstract class MyDataBase : RoomDatabase() {
return Room.databaseBuilder(
AbsMogoApplication.getApp()!!.applicationContext, MyDataBase::class.java, ROOT_PATH+roomName
)
.addMigrations(Migration1_2(1,2))
.addMigrations(Migration2_3(2,3))
.addMigrations(Migration3_4(3,4))
.addMigrations(Migration2_4(2,4))
.fallbackToDestructiveMigration()
.addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_2_3)
.addMigrations(MIGRATION_3_4)
.addMigrations(MIGRATION_4_5)
.build()
}
val ROOT_PATH = Environment.getExternalStorageDirectory().absolutePath + File.separator + "Mogo" + File.separator + "APP_cache" + File.separator //程序外部存储跟目录
@@ -105,32 +131,4 @@ abstract class MyDataBase : RoomDatabase() {
return field
}
}
class Migration1_2(val startVersion:Int,val endVersion:Int): Migration(startVersion,endVersion) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE ${EventDataBean.evnetDataTable} ADD COLUMN driver_id INTEGER");
}
}
class Migration2_3(val startVersion:Int,val endVersion:Int): Migration(startVersion,endVersion) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE ${SiteDataBean.siteDataTable} ADD COLUMN videoList TEXT");
database.execSQL("ALTER TABLE ${TaskSiteDataBean.usedTaskDataTable} ADD COLUMN videoList TEXT");
}
}
class Migration3_4(val startVersion:Int,val endVersion:Int): Migration(startVersion,endVersion) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE ${EventDataBean.evnetDataTable} ADD COLUMN msg_id TEXT")
database.execSQL("ALTER TABLE ${EventDataBean.evnetDataTable} ADD COLUMN update_time INTEGER")
}
}
class Migration2_4(val startVersion:Int,val endVersion:Int): Migration(startVersion,endVersion) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE ${SiteDataBean.siteDataTable} ADD COLUMN videoList TEXT");
database.execSQL("ALTER TABLE ${TaskSiteDataBean.usedTaskDataTable} ADD COLUMN videoList TEXT");
database.execSQL("ALTER TABLE ${EventDataBean.evnetDataTable} ADD COLUMN msg_id TEXT")
database.execSQL("ALTER TABLE ${EventDataBean.evnetDataTable} ADD COLUMN update_time INTEGER")
}
}
}

View File

@@ -0,0 +1,131 @@
package com.mogo.och.weaknet.repository.db.bean
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
/**
* 上报给服务器端的 选择线路、滑动出发、进站 完成线路的对象
*/
@Entity(tableName = WriteOffDataBean.writeoffDataTable)
data class WriteOffDataBean(
@PrimaryKey(autoGenerate = true) var id: Int = 0,
/**
* 二维码有效时间 时间戳 有效时间1分钟
*/
@ColumnInfo(name = "msg_id", typeAffinity = ColumnInfo.TEXT)
var msgId: String? = null,
/**
* 二维码有效时间 时间戳 有效时间1分钟
*/
@ColumnInfo(name = "expiry_time", typeAffinity = ColumnInfo.INTEGER)
var expiryTime: Long? = null,
/**
* 乘车日期
*/
@ColumnInfo(name = "booking_time", typeAffinity = ColumnInfo.INTEGER)
var bookingTime: Long? = null,
/**
* 校验接驳还是公交 shuttle bus
*/
@ColumnInfo(name = "type", typeAffinity = ColumnInfo.INTEGER)
var type: Int? = null,
/**
* 当前的任务id
*/
@ColumnInfo(name = "task_id", typeAffinity = ColumnInfo.INTEGER)
var taskId: Long? = null,
/**
* 校验线路Id
*/
@ColumnInfo(name = "line_id", typeAffinity = ColumnInfo.INTEGER)
var lineId: Long? = null,
/**
* 校验站点Id
*/
@ColumnInfo(name = "site_id", typeAffinity = ColumnInfo.INTEGER)
var siteId: Long? = null,
/**
* 司机id
*/
@ColumnInfo(name = "driver_id", typeAffinity = ColumnInfo.INTEGER)
var driverId: Long? = null,
/**
* 剩余核销次数>0
*/
@ColumnInfo(name = "remaining_times", typeAffinity = ColumnInfo.INTEGER)
var remainingTimes: Int? = null,
/**
* 订单号
*/
@ColumnInfo(name = "order_no", typeAffinity = ColumnInfo.TEXT)
var orderNo: String? = null,
/**
* uid
*/
@ColumnInfo(name = "uid", typeAffinity = ColumnInfo.TEXT)
var uid: String? = null,
/**
* 用户手机号
*/
@ColumnInfo(name = "seq", typeAffinity = ColumnInfo.TEXT)
var phone: String? = null,
/**
* 业务发生的时间
*/
@ColumnInfo(name = "business_time", typeAffinity = ColumnInfo.INTEGER)
var businessTime: Long? = null,
/**
* 票里人数
*/
@ColumnInfo(name = "tick_size", typeAffinity = ColumnInfo.INTEGER)
var ticketSize: Int? = null,
/**
* 票的类型
*/
@ColumnInfo(name = "tick_name", typeAffinity = ColumnInfo.TEXT)
var ticketName: String? = null,
/**
* 存储此条数据时时间戳
*/
@ColumnInfo(name = "event_save_time", typeAffinity = ColumnInfo.INTEGER, index = true)
val eventSaveTime: Long = System.currentTimeMillis(),
@ColumnInfo(name = "update_status", typeAffinity = ColumnInfo.INTEGER)
var updateStatus:Int = notUpdate,
@ColumnInfo(name = "update_time", typeAffinity = ColumnInfo.INTEGER)
var upDateTime:Long? = 0L,
) {
companion object {
const val writeoffDataTable: String = "writeoff_data_table"
// 没有上传
const val notUpdate = 0
// 上传中
const val updating = 1
// 已上传
const val updated = 2
const val daliXiaoChengXu = "ehsafety"
const val saasXiaoChengXu = "mogogosafety"
}
}

View File

@@ -0,0 +1,32 @@
package com.mogo.och.weaknet.repository.db.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.mogo.och.common.module.utils.DateTimeUtil
import com.mogo.och.weaknet.repository.db.bean.WriteOffDataBean
@Dao
interface WriteOffDataDao {
//插入数据
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg eventDataBean: WriteOffDataBean)
//删除数据
@Delete
fun delete(vararg eventDataBean: WriteOffDataBean)
@Query("SELECT * FROM ${WriteOffDataBean.writeoffDataTable} WHERE event_save_time > :zeroTime and order_no = :orderNo")
fun queryWriteOffByOrderNo(zeroTime: Long = DateTimeUtil.getCurrentDateZero(),orderNo:String): List<WriteOffDataBean>?
@Query("SELECT * FROM ${WriteOffDataBean.writeoffDataTable} order by event_save_time LIMIT 5 OFFSET 0")
fun queryLastDataByWaritData():List<WriteOffDataBean>?
@Query("SELECT * FROM ${WriteOffDataBean.writeoffDataTable} WHERE update_status = ${WriteOffDataBean.notUpdate} LIMIT 10 OFFSET 0")
fun queryWriteOffEventByStatusWithPage():List<WriteOffDataBean>?
}

View File

@@ -5,6 +5,7 @@ import com.mogo.och.common.module.manager.cache.OchSPManager
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
import com.mogo.och.common.module.manager.loop.BizLoopManager
import com.mogo.och.common.module.utils.DateTimeUtil
import com.mogo.och.weaknet.model.EventModel
import com.mogo.och.weaknet.repository.db.IDbRepository
import com.mogo.och.weaknet.repository.db.MyDataBase
import com.mogo.och.weaknet.repository.db.bean.EventDataBean
@@ -23,7 +24,6 @@ object EventDb: IDbRepository {
return field
}
var eventCallback: EventCallback? = null
override fun release(){
eventDataDao = null
@@ -44,7 +44,7 @@ object EventDb: IDbRepository {
event.msgId = "${OchSPManager.getSn()}_${DateTimeUtil.getCurrentTimeStamp()}"
BizLoopManager.runInIoThread {
eventDataDao?.insert(event)
eventCallback?.notifySyn()
EventModel.notifySyn()
}
}
@@ -70,7 +70,7 @@ object EventDb: IDbRepository {
event.msgId = "${OchSPManager.getSn()}_${DateTimeUtil.getCurrentTimeStamp()}"
BizLoopManager.runInIoThread {
eventDataDao?.insert(event)
eventCallback?.notifySyn()
EventModel.notifySyn()
}
}
@@ -96,7 +96,7 @@ object EventDb: IDbRepository {
event.msgId = "${OchSPManager.getSn()}_${DateTimeUtil.getCurrentTimeStamp()}"
BizLoopManager.runInIoThread {
eventDataDao?.insert(event)
eventCallback?.notifySyn()
EventModel.notifySyn()
}
}
@@ -115,7 +115,7 @@ object EventDb: IDbRepository {
event.msgId = "${OchSPManager.getSn()}_${DateTimeUtil.getCurrentTimeStamp()}"
BizLoopManager.runInIoThread {
eventDataDao?.insert(event)
eventCallback?.notifySyn()
EventModel.notifySyn()
}
}
@@ -149,9 +149,4 @@ object EventDb: IDbRepository {
return eventDataDao?.queryWaitUploadInfo()
}
interface EventCallback {
fun notifySyn()
}
}

View File

@@ -117,7 +117,7 @@ object TaskDb : IDbRepository {
OchChainLogManager.writeChainLogDb("开始任务", "异常情况${lineId}_${lineName}_task:${taskId} 为未使用的状态 原因:${e.message}")
}
}
return@flatMap Observable.error(DataException(DataException.startTaskErrorCode,e.message))
return@flatMap Observable.error(DataException(DataException.startTaskErrorCode,e.message?:""))
}
updateCount?.let {
if(it<=0){

View File

@@ -0,0 +1,48 @@
package com.mogo.och.weaknet.repository.db.repository
import com.mogo.och.weaknet.model.EventModel
import com.mogo.och.weaknet.repository.db.IDbRepository
import com.mogo.och.weaknet.repository.db.MyDataBase
import com.mogo.och.weaknet.repository.db.bean.WriteOffDataBean
import com.mogo.och.weaknet.repository.db.dao.WriteOffDataDao
object WriteOffDb: IDbRepository {
private var writeOffDataDao: WriteOffDataDao? = null
get() {
if(field==null){
field = MyDataBase.instance?.writeOffDataDao
register()
}
return field
}
override fun release(){
writeOffDataDao = null
}
fun addOrUpdate(vararg lineDataBean: WriteOffDataBean){
writeOffDataDao?.insert(*lineDataBean)
EventModel.notifySyn()
}
fun queryWaitUpdateEventCount(orderNo:String): WriteOffDataBean?{
val queryWriteOffByOrderNo = writeOffDataDao?.queryWriteOffByOrderNo(orderNo = orderNo)
if(!queryWriteOffByOrderNo.isNullOrEmpty()){
return queryWriteOffByOrderNo.last()
}
return null
}
fun queryWaitUpdateEvent(): List<WriteOffDataBean>? {
return writeOffDataDao?.queryWriteOffEventByStatusWithPage()
}
fun saveUpdateSuccess(writeOffEvents: List<WriteOffDataBean>) {
writeOffDataDao?.insert(*writeOffEvents.toTypedArray())
}
}

View File

@@ -8,6 +8,6 @@ data class PassengerWriteOffResponse(val data: Result?) : BaseData(){
val phone: String?,
val ticketSize: Int?,
val ticketName: String?,
val remainingTimes: Long?
val remainingTimes: Long?//剩余次数
)
}

View File

@@ -7,9 +7,16 @@ import com.mogo.commons.env.ProjectUtils
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.och.common.module.biz.login.LoginStatusManager
import com.mogo.och.common.module.manager.autopilot.line.LineManager
import com.mogo.och.common.module.manager.socket.lan.bean.WriteOffDetialMsg
import com.mogo.och.common.module.network.OchCommonServiceCallback
import com.mogo.och.common.module.utils.DateTimeUtil
import com.mogo.och.weaknet.bean.response.WriteOffCountResponse
import com.mogo.och.weaknet.model.LineModel
import com.mogo.och.weaknet.repository.db.bean.WriteOffDataBean
import com.mogo.och.weaknet.repository.db.repository.WriteOffDb
import com.mogo.och.weaknet.repository.exception.DataException
import com.mogo.och.weaknet.repository.net.exception.NetException
import com.mogo.och.weaknet.repository.net.NetInterface
import com.mogo.och.weaknet.repository.net.bean.response.PassengerWriteOffResponse
@@ -58,7 +65,108 @@ class WriteOffCacheRepository : IWriteOffRepository {
}
override fun writeOffEvent(writeOffDetialMsg: WriteOffDetialMsg): Observable<PassengerWriteOffResponse.Result>? {
TODO("Not yet implemented")
return Observable.just(writeOffDetialMsg)
.flatMap {
// 1、校验数据
/**
* 0、校验 tenantId
* 1、校验pipe 校验project
* 2、校验业务模式 bus和接驳
* 3、校验二维码有效性(向后1分钟有效)
* 4、校验乘车日期
* 5、校验线路
*
* 接驳
* 6、校验次数
* 7、同一个订单2分钟内只能执行一次
* 小巴
* 6、校验站点
*/
var lineId:Long?=null
var siteId:Long?=null
//
it.tenantId?.let { tenantId->
if(LoginStatusManager.getLoginInfo()?.tenantId==tenantId){
}else{
throw DataException(1012,"当前用户下单路线非当前的车辆所属公司")
}
}
// TODO: 校验project
if(ProjectUtils.isSaas()){
if(it.pipe != WriteOffDataBean.saasXiaoChengXu){
throw DataException(1012,"当前用户下单路线非当前的车辆所属公司")
}
}else if(ProjectUtils.isDali()){
if(it.pipe != WriteOffDataBean.daliXiaoChengXu){
throw DataException(1012,"当前用户下单路线非当前的车辆所属公司")
}
}
// 2、校验 bus和shuttle
if (LoginStatusManager.getBusInessType().name.lowercase()!=it.typeBiz) {
throw DataException(1005,"车辆未登录、或没有任务")
}
// 3 二维码1分钟失效
if(System.currentTimeMillis()-(it.expiryTime?:0L)>60_000){
throw DataException(6001,"二维码已过期")
}
// 4 校验乘车日期
if(!DateTimeUtil.isSameDay(System.currentTimeMillis(),it.bookingTime?:0)){
throw DataException(1009,"车票所选乘车日期非今日")
}
// 5、校验线路
if(it.lineId==LineManager.lineInfos?.lineId){
lineId = it.lineId
}else{
throw DataException(1006,"车票路线信息与当前车辆执行任务的路线信息不符合")
}
if(AppIdentityModeUtils.isShuttle(FunctionBuildConfig.appIdentityMode)) {
// 6、校验次数
if((it.remainingTimes?:0)<=0){
throw DataException(1008,"车票剩余可用次数为0")
}
// 7、同一个订单2分钟内只能核销一次
if (!it.orderNo.isNullOrEmpty()) {
val lastWriteOff = WriteOffDb.queryWaitUpdateEventCount(it.orderNo!!)
if(lastWriteOff!=null){
if(System.currentTimeMillis()-lastWriteOff.eventSaveTime<=120_000){
throw DataException(6002,"同一订单核销间隔时间需大于2分钟")
}
}
}else{
throw DataException(11000,"缺少orderNo")
}
}else if(AppIdentityModeUtils.isBus(FunctionBuildConfig.appIdentityMode)) {
val (start, _) = LineManager.getStations()
if(start?.siteId?.toLong()==it.startStationId){
siteId = it.startStationId
}else{
throw DataException(1006,"车票站点信息与当前车辆执行任务的站点信息不符合")
}
}
val addWrite = WriteOffDataBean()
addWrite.expiryTime = it.expiryTime
addWrite.bookingTime = it.bookingTime
addWrite.type = it.type
addWrite.taskId = LineModel.currentTask?.taskId
addWrite.lineId = lineId
addWrite.siteId = siteId
addWrite.remainingTimes = it.remainingTimes
addWrite.orderNo = it.orderNo
addWrite.uid = it.uid
addWrite.phone = it.phone
addWrite.ticketSize = it.ticketSize
addWrite.ticketName = it.ticketName
WriteOffDb.addOrUpdate()
val reslut = PassengerWriteOffResponse.Result(it.phone,it.ticketSize,it.ticketName,it.remainingTimes?.toLong())
return@flatMap Observable.just(reslut)
}
}
override fun release() {