diff --git a/entry/src/main/ets/api/judge.ets b/entry/src/main/ets/api/judge.ets index 2f4a002..fab8d59 100644 --- a/entry/src/main/ets/api/judge.ets +++ b/entry/src/main/ets/api/judge.ets @@ -6,6 +6,8 @@ import { GetSyncData } from '../utils/table/Operation'; import { GetCurrentTime } from '../utils/Common'; import FileUtils from '../utils/FileUtils'; import common from '@ohos.app.ability.common'; +import { dConsole } from '../utils/LogWorker'; +import { JudgeTag } from '../config'; let baseHost: string = AppStorage.get('host')!; @@ -35,43 +37,39 @@ export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath return { code: 1 } } let JGHOST: string = AppStorage.get("JGHOST") || "" + let isJGNew: boolean = false //获取监管接口地址路径 if (!JGHOST) { const syssetParams: MASYSSETTableType[] = await GetSyncData("MA_SYSSET"); - syssetParams.forEach(sys => { if (sys.v_no == '839') { //是否是新监管 - // globalThis.isJGNew = sys.v_value == '3' - AppStorage.setOrCreate('isJGNew', sys.v_value == '3') + isJGNew = sys.v_value == '3' + AppStorage.setOrCreate('isJGNew', isJGNew) } if (sys.v_no == '900') { - // globalThis.JGHOST = validateIP(decodeURIComponent(sys.v_value)) - AppStorage.setOrCreate('JGHOST', validateIP(decodeURIComponent(sys.v_value || ""))) + const ip = decodeURIComponent(sys.v_value || "") + JGHOST = validateIP(ip) || "" + dConsole.log(JudgeTag, "监管地址取值", JGHOST) + AppStorage.setOrCreate('JGHOST', JGHOST) } }) } - // const { xtlb, jkxlh, jkid, drvexam } = params; - const isJGNew: boolean = AppStorage.get('isJGNew') || false //新监管调用 if (isJGNew) { + dConsole.log(JudgeTag, "新监管") return await writeObjectOutNew(params, filePath, context) } params.drvexam = params.drvexam ?? {}; params.drvexam.zp = params.drvexam.zp === undefined ? undefined : encodeURIComponent(params.drvexam.zp); - const drvexamArrs = Object.entries(params.drvexam) + const drvexamArr = Object.entries(params.drvexam) .filter((item: [string, string]) => item[1] != undefined) .map((item: [string, object]) => `<${item[0]}>${item[1]}`) - // const drvexamArrs = Reflect.ownKeys(params.drvexam) - // .filter(dKey => Reflect.get(params.drvexam, dKey) != undefined) - // .map((key: string) => ( - // `<${key}>${Reflect.get(params.drvexam, key)}`)); if (filePath) { const fileUtil = new FileUtils(context); await fileUtil.initFolder(filePath); - let obj: WuxiExamType = { xtlb: params.xtlb, jkxlh: params.jkxlh, @@ -83,9 +81,8 @@ export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath } fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(obj) + `\n`); } - + dConsole.log(JudgeTag, "老监管", JGHOST) //对象转换成xml - JGHOST = AppStorage.get("JGHOST") || "" const temp = await request({ host: JGHOST, url: '/dems_ws/services/TmriOutAccess?wsdl', @@ -105,7 +102,7 @@ export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath - ${drvexamArrs} + ${drvexamArr} ]]> @@ -262,11 +259,6 @@ export async function uploadExamMileage(params: UploadExamMileage) { // }) // } -function validateIP(path: string) { - const reg = new RegExp(`(\w+):\/\/([^/:]+)(:\d*)?`) - const result = path.match(reg); - return result ? result[0] : ""; -} // 上传运行时常 export async function uploadHarmonyLiCheng(data: object) { @@ -277,3 +269,11 @@ export async function uploadHarmonyLiCheng(data: object) { xml: false }) } + + +function validateIP(path: string) { + // const regex = /(\w+):\/\/([\d.]+)(:\d+)?/; + const regex = new RegExp("(\\w+):\\/\\/([\\d.]+)(:\\d+)?"); + const result = path.match(regex); + return result ? result[0] : null; +} diff --git a/entry/src/main/ets/pages/ExaminerLogin.ets b/entry/src/main/ets/pages/ExaminerLogin.ets index c67111e..5e03f82 100644 --- a/entry/src/main/ets/pages/ExaminerLogin.ets +++ b/entry/src/main/ets/pages/ExaminerLogin.ets @@ -132,7 +132,13 @@ struct ExaminerLoginPage { const endTime = new Date().getTime(); const elapsedTime = endTime - startTime; const remainingTime = Math.max(0, minDisplayTime - elapsedTime); - + const examinerLoginInfo: ExaminerLoginInfo | undefined = res.examinerLoginRsp?.body; + if (!examinerLoginInfo) { + dConsole.error(ExaminerLoginTag, 'examinerLoginRsp.body is undefined'); + return; + } + examinerLoginInfo.username = this.userName; + AppStorage.setOrCreate('examinerInfo', examinerLoginInfo); // 延迟关闭弹窗和跳转 setTimeout(() => { this.loadingDialog.close(); @@ -142,14 +148,6 @@ struct ExaminerLoginPage { type: 1 } }, router.RouterMode.Single); - - const examinerLoginInfo: ExaminerLoginInfo | undefined = res.examinerLoginRsp?.body; - if (!examinerLoginInfo) { - dConsole.error(ExaminerLoginTag, 'examinerLoginRsp.body is undefined'); - return; - } - examinerLoginInfo.username = this.userName; - AppStorage.setOrCreate('examinerInfo', examinerLoginInfo); }, remainingTime); } catch (e) { diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 837f9d1..872a69d 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -206,7 +206,7 @@ struct Index { this.initWork = true } DifferentialAndSignal.onMsg(() => { - dConsole.log("外层接受") + // dConsole.log("外层接受") }) } diff --git a/entry/src/main/ets/pages/UserInfo.ets b/entry/src/main/ets/pages/UserInfo.ets index 86a491c..309bd87 100644 --- a/entry/src/main/ets/pages/UserInfo.ets +++ b/entry/src/main/ets/pages/UserInfo.ets @@ -41,7 +41,7 @@ import { GetCurrentTime, NumberToByteArray } from '../utils/Common'; import DB from '../utils/DbSql'; import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness'; import { JudgeEmitterInstance } from '../utils/business/UdpEvent'; -import { JudgeConfig, StartExamTag } from '../config'; +import { JudgeConfig, StartExamTag, UserInfoTag } from '../config'; import { dConsole } from '../utils/LogWorker'; import HeaderComponent from './compontents/Header'; import AvatarComponent from './UserInfo/Avatar'; @@ -778,7 +778,7 @@ struct UserInfoPage { sfzmhm: this.currentUser.sfzmhm, examinationRoomId: this.carInfo.examinationRoomId || "", username: this.examinerLoginInfo.username || "", - lsh: this.lsh + lsh: this.lsh, } dConsole.log('carNo1111', param) examinationStuAbsent(param).then(res => { @@ -800,6 +800,7 @@ struct UserInfoPage { this.pageIndex = 0 this.qkFlag = false this.currentUser = EmptyCandidateObject + this.missAnExamDialogController.close() this.getExaminationStudentInfoFn() return } @@ -854,9 +855,8 @@ struct UserInfoPage { avPlayer.playAudio([`voice/监管通信中.mp3`], false, async () => { dConsole.info('surenjun', '播放结束开始考试接口调用') - // const { code, keystr, message } = await this.beginExam() || {}; const res = await this.beginExam() - dConsole.info('surenjun', '开始考试接口调用结束') + dConsole.info('surenjun', '开始考试接口调用结束', JSON.stringify(res)) //TODO code转换 if (res.code != 1) { @@ -1007,7 +1007,7 @@ struct UserInfoPage { return { code: -200 } } const drvexam: DrvexamType = { - lsh: "this.currentUser.lsh", + lsh: this.currentUser.lsh, kskm: this.carInfo.examSubject, ksxtbh: this.ksxtbh || '222', sfzmhm: this.currentUser.sfzmhm || '', @@ -1216,6 +1216,7 @@ struct UserInfoPage { .margin({ bottom: 21 }) .onClick(async () => { if (this.systemParam.Param612Str == '1') { + dConsole.log(UserInfoTag, "不给开始考试") return } await this.prePareExam() diff --git a/entry/src/main/ets/utils/Request.ets b/entry/src/main/ets/utils/Request.ets index 2fb932d..775e119 100644 --- a/entry/src/main/ets/utils/Request.ets +++ b/entry/src/main/ets/utils/Request.ets @@ -3,6 +3,7 @@ import convertxml from '@ohos.convertxml'; import { BusinessError } from '@ohos.base'; import promptAction from '@ohos.promptAction'; import { RequestTag } from '../config'; +import Prompt from '@system.prompt'; interface RequestOption { url: string @@ -112,7 +113,32 @@ function dealCenterCode(message: string, isNewCenter: boolean = false): CenterCo } } } - return undefined + const result = parseXml(message) + if (result.code != '1') { + Prompt.showToast({ + message: decodeURIComponent(message as string), + duration: 3000 + }); + return { code: result.code, message: decodeURIComponent(result.message || "") } as CenterCodeResult + } else { + return result + } +} + +function parseXml(xml: string) { + const codeRegex = new RegExp("(.*?)<\\/code>"); + const messageRegex = new RegExp("(.*?)<\\/message>"); + const keystrRegex = new RegExp("(.*?)<\\/keystr>"); + + const codeMatch = xml.match(codeRegex); + const messageMatch = xml.match(messageRegex); + const keystrMatch = xml.match(keystrRegex); + + return { + code: codeMatch ? codeMatch[1] : null, + message: messageMatch ? messageMatch[1] : null, + keystr: keystrMatch ? keystrMatch[1] : null, + } as CenterCodeResult; } type RequestResult = Object | object | string | CenterCodeResult @@ -134,9 +160,9 @@ export default function Request(options: RequestOption) readTimeout: options.timeout || 30 * 1000 }).then(async data => { console.log(RequestTag, baseURL, options.url, "返回的数据", JSON.stringify(data)) - // let result = options.xml ? xmlToJSON(data.result as string) : data.result + console.log(RequestTag, baseURL, options.url, "入参", options.accept, "xml", options.xml) let result = options.xml ? (options.accept ? data.result : xmlToJSON(data.result as string)) : data.result; - console.log("结束xml解析") + console.log("结束xml解析", JSON.stringify(result)) let resObj: object = new Object() if (typeof result === 'string') { result = JSON.parse(result)