tcp 错误判断修改
This commit is contained in:
parent
2119758411
commit
f61665a59f
@ -4,15 +4,6 @@ import prompt from '@ohos.prompt';
|
|||||||
import { tcpUtil } from './TcpRequest';
|
import { tcpUtil } from './TcpRequest';
|
||||||
import Prompt from '@system.prompt';
|
import Prompt from '@system.prompt';
|
||||||
import tempRequest from './tempRequest';
|
import tempRequest from './tempRequest';
|
||||||
import connection from '@ohos.net.connection';
|
|
||||||
import { TempLogger } from './TempLogger';
|
|
||||||
import { dateFormat } from './tools';
|
|
||||||
import { voiceService } from '../service/voiceService';
|
|
||||||
|
|
||||||
let vs = new voiceService(() => {
|
|
||||||
})
|
|
||||||
|
|
||||||
export let isError = false
|
|
||||||
|
|
||||||
function tcpRequest<T>(req: any): Promise<T> {
|
function tcpRequest<T>(req: any): Promise<T> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -99,106 +90,15 @@ function tcpRequest<T>(req: any): Promise<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function request<T>(req: any): Promise<T> {
|
export default async function request<T>(req: any): Promise<T> {
|
||||||
// return tcpRequest<T>(req)
|
return new Promise((resolve, reject) => {
|
||||||
// return new Promise((resolve, reject) => {
|
tempRequest(req).then((response) => {
|
||||||
// tempRequest(req).then((response) => {
|
console.log("[http request] only http request success")
|
||||||
// console.log("[http request] only http request success")
|
resolve(response as T)
|
||||||
// resolve(response as T)
|
}).catch(err => {
|
||||||
// }).catch(err => {
|
console.log("[http request] only http request error")
|
||||||
// console.log("[http request] only http request error")
|
reject(err)
|
||||||
// reject(err)
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// return tempRequest<T>(req)
|
|
||||||
if (!isError) {
|
|
||||||
return new Promise<T>((resolve, reject) => {
|
|
||||||
console.log("[http request] url: " + req.url)
|
|
||||||
console.log("[http request] http request start")
|
|
||||||
tempRequest<T>(req).then((response) => {
|
|
||||||
console.log("[http request] http request success")
|
|
||||||
resolve(response)
|
|
||||||
}).catch((error) => {
|
|
||||||
isError = true
|
|
||||||
connection.getDefaultNet((error: any, data: any) => {
|
|
||||||
if (error) {
|
|
||||||
console.error(`Failed Http. Code:${error.code}, message:${error.message}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log("Http success" + JSON.stringify(data));
|
|
||||||
});
|
|
||||||
console.log("[http request] http request error: " + JSON.stringify(error))
|
|
||||||
console.log("[http request] start tcp resend")
|
|
||||||
tcpRequest<T>(req).then(response => {
|
|
||||||
console.log("[http request] tcp resend success")
|
|
||||||
resolve(response as T)
|
|
||||||
}).catch(err => {
|
|
||||||
console.log("[http request] tcp resend failed: " + JSON.stringify(err))
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
} else {
|
})
|
||||||
console.log("[http request] url: " + req.url)
|
|
||||||
console.log("[http request] only tcp request start")
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
tcpRequest(req).then(res => {
|
|
||||||
console.log("[http request] only tcp request success")
|
|
||||||
resolve(res as T)
|
|
||||||
}).catch(err => {
|
|
||||||
console.log("[http request] only tcp request error")
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// if (!isError) {
|
|
||||||
// return new Promise<T>((resolve, reject) => {
|
|
||||||
// console.log("[http request] url: " + req.url)
|
|
||||||
// console.log("[http request] tcp request start")
|
|
||||||
// tcpRequest<T>(req).then((response) => {
|
|
||||||
// console.log("[http request] tcp request success")
|
|
||||||
// resolve(response)
|
|
||||||
// }).catch((error) => {
|
|
||||||
// if (error.code === 2300007) {
|
|
||||||
// isError = true
|
|
||||||
// }
|
|
||||||
// connection.getDefaultNet((error: any, data: any) => {
|
|
||||||
// if (error) {
|
|
||||||
// console.error(`Failed Http. Code:${error.code}, message:${error.message}`);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// console.log("Http success" + JSON.stringify(data));
|
|
||||||
// });
|
|
||||||
// console.log("[http request] tcp request error: " + JSON.stringify(error))
|
|
||||||
// console.log("[http request] start http resend")
|
|
||||||
// tempRequest<T>(req).then(response => {
|
|
||||||
// console.log("[http request] http resend success")
|
|
||||||
// resolve(response as T)
|
|
||||||
// }).catch(err => {
|
|
||||||
// TempLogger.error(JSON.stringify({
|
|
||||||
// time: dateFormat(new Date()),
|
|
||||||
// error: JSON.stringify(error),
|
|
||||||
// params: JSON.stringify(req)
|
|
||||||
// }))
|
|
||||||
// console.log("[http request] http resend failed: " + JSON.stringify(err))
|
|
||||||
// reject(err)
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// } else {
|
|
||||||
// console.log("[http request] url: " + req.url)
|
|
||||||
// console.log("[http request] only http request start")
|
|
||||||
// return new Promise((resolve, reject) => {
|
|
||||||
// tempRequest(req).then((response) => {
|
|
||||||
// console.log("[http request] only http request success")
|
|
||||||
// resolve(response as T)
|
|
||||||
// }).catch(err => {
|
|
||||||
// console.log("[http request] only http request error")
|
|
||||||
// reject(err)
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//xml格式转JSON
|
//xml格式转JSON
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import { tcpUtil } from '../common/utils/TcpRequest';
|
|||||||
import { TempLogger } from '../common/utils/TempLogger';
|
import { TempLogger } from '../common/utils/TempLogger';
|
||||||
import DB from '../common/database/DbSql';
|
import DB from '../common/database/DbSql';
|
||||||
import { initTable } from '../common/service/initable';
|
import { initTable } from '../common/service/initable';
|
||||||
|
import Want from '@ohos.app.ability.Want';
|
||||||
|
|
||||||
export default class EntryAbility extends UIAbility {
|
export default class EntryAbility extends UIAbility {
|
||||||
async onCreate(want, launchParam) {
|
async onCreate(want, launchParam) {
|
||||||
@ -27,10 +28,16 @@ export default class EntryAbility extends UIAbility {
|
|||||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy() {
|
async onDestroy() {
|
||||||
const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00]
|
const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00]
|
||||||
const arrCloseBuffer = Array2Byte(arrClose).buffer
|
const arrCloseBuffer = Array2Byte(arrClose).buffer
|
||||||
globalThis?.lightLineUdp?.send(arrCloseBuffer);
|
globalThis?.lightLineUdp?.send(arrCloseBuffer);
|
||||||
|
let want: Want = {
|
||||||
|
deviceId: '',
|
||||||
|
bundleName: 'com.oh.dts',
|
||||||
|
abilityName: 'ServiceExtAbility'
|
||||||
|
};
|
||||||
|
await this.context.stopServiceExtensionAbility(want)
|
||||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -284,7 +284,8 @@ struct Index {
|
|||||||
// type: 1,
|
// type: 1,
|
||||||
// name: 'button_media.wav'
|
// name: 'button_media.wav'
|
||||||
// })
|
// })
|
||||||
router.back()
|
let ctx = getContext(this) as common.UIAbilityContext
|
||||||
|
ctx.terminateSelf()
|
||||||
})
|
})
|
||||||
}.position({ y: 265 * this.ratio * this.dialogRatio, x: 115 * this.ratio * this.dialogRatio })
|
}.position({ y: 265 * this.ratio * this.dialogRatio, x: 115 * this.ratio * this.dialogRatio })
|
||||||
|
|
||||||
|
|||||||
@ -54,7 +54,6 @@ import {
|
|||||||
examJudgeVersion
|
examJudgeVersion
|
||||||
} from './api/index';
|
} from './api/index';
|
||||||
import { getSyncData, upDateTableByArray } from '../../common/service/initable';
|
import { getSyncData, upDateTableByArray } from '../../common/service/initable';
|
||||||
import { isError } from '../../common/utils/request';
|
|
||||||
|
|
||||||
const judgeTag = 'SURENJUN_JUDGE'
|
const judgeTag = 'SURENJUN_JUDGE'
|
||||||
|
|
||||||
@ -488,7 +487,7 @@ export default class Judge {
|
|||||||
const msgStr = strArr[num];
|
const msgStr = strArr[num];
|
||||||
if (msgStr == '') {
|
if (msgStr == '') {
|
||||||
console.info(judgeTag, '模拟数据考试结束')
|
console.info(judgeTag, '模拟数据考试结束')
|
||||||
globalThis.windowClass.setWindowSystemBarEnable(['navigation'])
|
globalThis.windowClass.setWindowSystemBarEnable([])
|
||||||
clearInterval(judgeTimer)
|
clearInterval(judgeTimer)
|
||||||
this.checkExamIsEnd(true)
|
this.checkExamIsEnd(true)
|
||||||
return
|
return
|
||||||
@ -1400,9 +1399,6 @@ export default class Judge {
|
|||||||
this.isUdpEnd = true;
|
this.isUdpEnd = true;
|
||||||
closeAllFiles()
|
closeAllFiles()
|
||||||
router.back();
|
router.back();
|
||||||
if(isError) {
|
|
||||||
globalThis.context.terminateSelf()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
throw new Error('End Loop')
|
throw new Error('End Loop')
|
||||||
}
|
}
|
||||||
@ -1412,9 +1408,6 @@ export default class Judge {
|
|||||||
this.isUdpEnd = true;
|
this.isUdpEnd = true;
|
||||||
closeAllFiles()
|
closeAllFiles()
|
||||||
router.back();
|
router.back();
|
||||||
if(isError) {
|
|
||||||
globalThis.context.terminateSelf()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
throw new Error('End Loop')
|
throw new Error('End Loop')
|
||||||
}
|
}
|
||||||
@ -1429,9 +1422,6 @@ export default class Judge {
|
|||||||
this.isUdpEnd = true
|
this.isUdpEnd = true
|
||||||
closeAllFiles()
|
closeAllFiles()
|
||||||
router.back();
|
router.back();
|
||||||
if(isError) {
|
|
||||||
globalThis.context.terminateSelf()
|
|
||||||
}
|
|
||||||
}, param302 == 8 ? 3000 : 0)
|
}, param302 == 8 ? 3000 : 0)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user