fix: 添加ApiResponseType类型定义,优化相关函数的返回类型和参数类型
This commit is contained in:
parent
d803502e61
commit
6e1c80cb04
@ -1,6 +1,6 @@
|
||||
import request from '../utils/Request'
|
||||
import http from '@ohos.net.http'
|
||||
import { CarCheckDataType, CarConfigurationInfoResponse, DeviceParamType, RegistrationDeviceNoRsp } from '../model'
|
||||
import { ApiResponseType, CarCheckDataType, CarConfigurationInfoResponse, DeviceParamType } from '../model'
|
||||
|
||||
export async function carConfigurationInfo(params: object): Promise<CarConfigurationInfoResponse> {
|
||||
return request<CarConfigurationInfoResponse>({
|
||||
@ -13,7 +13,7 @@ export async function carConfigurationInfo(params: object): Promise<CarConfigura
|
||||
|
||||
//设备注册
|
||||
export async function registrationDeviceNo(params: DeviceParamType) {
|
||||
return request<RegistrationDeviceNoRsp>({
|
||||
return request<ApiResponseType>({
|
||||
url: '/der2/services/exam/registrationDeviceNo.ws',
|
||||
data: `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<registrationDeviceNoReq>
|
||||
@ -28,7 +28,7 @@ export async function registrationDeviceNo(params: DeviceParamType) {
|
||||
|
||||
//自检结果上传
|
||||
export async function uploadExamCarCheckResult(params: CarCheckDataType) {
|
||||
return request<object>({
|
||||
return request<ApiResponseType>({
|
||||
url: '/der2/services/exam/uploadExamCarCheckResult.ws',
|
||||
data: `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<uploadExamCarCheckResultReq>
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
import request from "../utils/Request"
|
||||
import http from "@ohos.net.http"
|
||||
import { InitializeTheCentralTableType, ObtainCarExamInfoParams, ResponseDataType } from "../model"
|
||||
import {
|
||||
ApiResponseType,
|
||||
InitializeTheCentralTableType,
|
||||
ObtainCarExamInfoParams,
|
||||
ResponseDataType,
|
||||
TimeSynchronizationParams,
|
||||
TimeSynchronizationRspBody
|
||||
} from "../model"
|
||||
|
||||
interface timeSynchronizationParams {
|
||||
time: string
|
||||
deviceNo: string
|
||||
version: string
|
||||
judgeVersion: string
|
||||
}
|
||||
|
||||
//同步时间
|
||||
export async function timeSynchronization(params: timeSynchronizationParams) {
|
||||
return request<object>({
|
||||
export async function timeSynchronization(params: TimeSynchronizationParams) {
|
||||
return request<ApiResponseType>({
|
||||
url: '/der2/services/exam/timeSynchronization.ws',
|
||||
data: `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<timeSynchronizationReq>
|
||||
@ -35,7 +36,7 @@ interface timeSynchronizationHTTPParams {
|
||||
|
||||
//同步时间
|
||||
export async function timeSynchronizationHTTP(params: timeSynchronizationHTTPParams) {
|
||||
return request<object>({
|
||||
return request<ApiResponseType>({
|
||||
url: '/der2/services/exam/timeSynchronization.ws',
|
||||
data: `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<timeSynchronizationReq>
|
||||
@ -53,7 +54,7 @@ export async function timeSynchronizationHTTP(params: timeSynchronizationHTTPPar
|
||||
|
||||
//获取考车信息
|
||||
export async function obtainCarExamInfo(params: ObtainCarExamInfoParams) {
|
||||
return request<object>({
|
||||
return request<ApiResponseType>({
|
||||
url: '/der2/services/exam/obtainCarExamInfo.ws',
|
||||
data: `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<obtainCarExamInfoReq>
|
||||
@ -84,7 +85,7 @@ export async function initCarInfoCache(params: initCarInfoCacheParams) {
|
||||
|
||||
//参数下发读表接口
|
||||
export async function initCenterCache(params: object, url: string) {
|
||||
const timeInfo: string = AppStorage.get('timeInfo')
|
||||
const timeInfo: TimeSynchronizationRspBody = AppStorage.get<TimeSynchronizationRspBody>('timeInfo')
|
||||
return await request<object>({
|
||||
url: '/para/initCenterCache.ws',
|
||||
data: params,
|
||||
@ -107,13 +108,15 @@ export async function initCenterCacheByKSPT(params: object, url: string) {
|
||||
|
||||
|
||||
//从参数平台获取模型
|
||||
export async function initEsModel(params) {
|
||||
// TODO 类型需要补全
|
||||
export async function initEsModel(params: ESObject) {
|
||||
const timeInfo: TimeSynchronizationRspBody = AppStorage.get<TimeSynchronizationRspBody>('timeInfo')
|
||||
return await request<object>({
|
||||
url: '/para/initEsModel.ws',
|
||||
data: params,
|
||||
method: http.RequestMethod.POST,
|
||||
xml: false,
|
||||
host: globalThis.timeInfo.url as string,
|
||||
host: timeInfo.url as string,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -72,49 +72,48 @@ export function dateVersionFormat(t) {
|
||||
return year + "." + fill(month) + "." + fill(day) + "." + fill(hours);
|
||||
}
|
||||
|
||||
|
||||
//同步时时间
|
||||
// export async function timeSynchronize() {
|
||||
// let date = new Date();
|
||||
// console.info('jiangsong1:timeSynchronization begin ');
|
||||
//
|
||||
// let params = {
|
||||
// time: dateFormat(date),
|
||||
// deviceNo: AppStorage.get('deviceNo'),
|
||||
// version: AppStorage.get('baseInfo').version,
|
||||
// judgeVersion: AppStorage.get('baseInfo').judgeVersion
|
||||
// }
|
||||
// let res: any = await timeSynchronization(params)
|
||||
// res = res.timeSynchronizationRsp;
|
||||
// AppStorage.setOrCreate('timeInfo', res.body)
|
||||
//
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
|
||||
// export async function setCurrentTime(): Promise<void> {
|
||||
// let res = await timeSynchronize();
|
||||
// let currentTime = res.head.time;
|
||||
// let times = new Date(currentTime).getTime();
|
||||
// console.log('jiangsong:times==' + times);
|
||||
// try {
|
||||
// await systemTime.setTime(times);
|
||||
// // systemTime.setTime(times).then(() => {
|
||||
// // console.info(`Succeeded in setting time.`);
|
||||
// // }).catch((error) => {
|
||||
// // console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`);
|
||||
// // });
|
||||
// } catch (e) {
|
||||
// console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
|
||||
// }
|
||||
// }
|
||||
enum timeType {
|
||||
fulltime = 1
|
||||
}
|
||||
|
||||
//同步时时间
|
||||
export async function timeSynchronize() {
|
||||
let date = new Date();
|
||||
console.info('jiangsong1:timeSynchronization begin ');
|
||||
|
||||
let params = {
|
||||
time: dateFormat(date),
|
||||
deviceNo: AppStorage.get('deviceNo'),
|
||||
version: AppStorage.get('baseInfo').version,
|
||||
judgeVersion: AppStorage.get('baseInfo').judgeVersion
|
||||
}
|
||||
let res: any = await timeSynchronization(params)
|
||||
res = res.timeSynchronizationRsp;
|
||||
AppStorage.setOrCreate('timeInfo', res.body)
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function setCurrentTime(): Promise<void> {
|
||||
let res = await timeSynchronize();
|
||||
let currentTime = res.head.time;
|
||||
let times = new Date(currentTime).getTime();
|
||||
console.log('jiangsong:times==' + times);
|
||||
try {
|
||||
await systemTime.setTime(times);
|
||||
// systemTime.setTime(times).then(() => {
|
||||
// console.info(`Succeeded in setting time.`);
|
||||
// }).catch((error) => {
|
||||
// console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`);
|
||||
// });
|
||||
} catch (e) {
|
||||
console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
|
||||
}
|
||||
}
|
||||
|
||||
//获取当前时间并转化
|
||||
export async function getCurrentTime(type?: timeType): Promise<string> {
|
||||
|
||||
const date = await systemTime.getDate();
|
||||
const year = date.getFullYear();
|
||||
let month = date.getMonth() + 1;
|
||||
|
||||
@ -1,24 +1,82 @@
|
||||
import { DrvexamType } from ".";
|
||||
|
||||
export interface RegistrationDeviceNoRsp {
|
||||
registrationDeviceNoRsp: RegistrationDeviceNoRspDetails;
|
||||
// -----new-----
|
||||
export interface ApiResponseType {
|
||||
//获取考车信息 /der2/services/exam/obtainCarExamInfo.ws
|
||||
obtainCarExamInfoRsp?: ObtainCarExamInfoRsp
|
||||
// 自检结果上传 /der2/services/exam/uploadExamCarCheckResult.ws
|
||||
uploadExamCarCheckResultRsp?: UploadExamCarCheckResultRsp
|
||||
// 设备注册 /der2/services/exam/registrationDeviceNo.ws
|
||||
registrationDeviceNoRsp?: RegistrationDeviceNoRspDetails;
|
||||
|
||||
// 时间同步 /der2/services/exam/timeSynchronization.ws
|
||||
timeSynchronizationRsp?: TimeSynchronizationRsp;
|
||||
}
|
||||
|
||||
interface RegistrationDeviceNoRspDetails {
|
||||
head: Head;
|
||||
interface TimeSynchronizationRsp {
|
||||
head: Head
|
||||
body: TimeSynchronizationRspBody
|
||||
}
|
||||
|
||||
export interface TimeSynchronizationRspBody {
|
||||
mode?: string;
|
||||
url?: string
|
||||
}
|
||||
|
||||
interface UploadExamCarCheckResultRsp {
|
||||
head: Head
|
||||
}
|
||||
|
||||
|
||||
interface ObtainCarExamInfoRsp {
|
||||
head: Head
|
||||
body?: ObtainCarExamInfoRspBody
|
||||
}
|
||||
|
||||
export interface ObtainCarExamInfoRspBody {
|
||||
carId: string;
|
||||
carIp: string;
|
||||
carNo: string;
|
||||
examSubject: string;
|
||||
examinationRoomId: string;
|
||||
gpsAddress: string;
|
||||
hintPort: string;
|
||||
isNeedCheck: string;
|
||||
ksdd: string;
|
||||
messagePort: string;
|
||||
plateNo: string;
|
||||
udpAddress: string;
|
||||
voicePort: string;
|
||||
}
|
||||
|
||||
export interface TimeSynchronizationParams {
|
||||
time: string
|
||||
deviceNo: string
|
||||
version: string
|
||||
judgeVersion: string
|
||||
}
|
||||
|
||||
interface Head {
|
||||
resultCode: string;
|
||||
time: string;
|
||||
resultMessage: string;
|
||||
checkCode: string;
|
||||
}
|
||||
|
||||
// -----new-----
|
||||
|
||||
|
||||
interface RegistrationDeviceNoRspDetails {
|
||||
head: Head;
|
||||
}
|
||||
|
||||
|
||||
interface ImageCompareRsp {
|
||||
head: Head;
|
||||
body: ESObject
|
||||
}
|
||||
|
||||
|
||||
export interface GetExaminationStudentInfoResponse {
|
||||
getExaminationStudentInfoRsp: ImageCompareRsp
|
||||
}
|
||||
@ -117,4 +175,6 @@ interface GetExaminationItemRspDetails {
|
||||
|
||||
interface GetExaminationItemRspBody {
|
||||
ykxx: string;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import testNapi from '@ohos.hiserialsdk';
|
||||
import { dateFormat } from '../common/utils/tools';
|
||||
import { DwMapData, PassData, RealNumData, StackValueData, WarnFlagData, WarnFlagTipData } from '../mock';
|
||||
import { BaseInfoType } from '../model/Common';
|
||||
import { CarCheckDataType, CarConfigurationParams, CarInfoType } from '../model/CarCheck';
|
||||
import { CarCheckDataType, CarConfigurationParams, CarInfoType } from '../model';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import { SpzdType } from '../model';
|
||||
|
||||
@ -296,6 +296,7 @@ struct Index {
|
||||
}
|
||||
this.stopCheck()
|
||||
uploadExamCarCheckResult(data).then((res) => {
|
||||
// TODO 需要提示
|
||||
})
|
||||
}
|
||||
}, parseInt(this.checkListCopy[0].time) * 1000)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import common from '@ohos.app.ability.common';
|
||||
import router from '@ohos.router';
|
||||
|
||||
import { getCurrentTime, setCurrentTime, string2Bytes } from '../common/utils/tools';
|
||||
import { getCurrentTime, string2Bytes } from '../common/utils/tools';
|
||||
import { FileHelper } from '../common/service/FileHelper';
|
||||
import { getEsCarModel, getSyncData, } from '../common/service/initable';
|
||||
import { getUDP, getUDP2 } from '../common/utils/GlobalUdp';
|
||||
@ -18,7 +18,7 @@ import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
|
||||
import { BaseInfoType } from '../model/Common';
|
||||
import { CarInfoType } from '../model';
|
||||
import { InitializeTheCentralTableType, MASYSSETTableType, TimeInfo } from '../model';
|
||||
import { GetCarInfo, GetDeviceInfo, UseAuth } from './Index/utils';
|
||||
import { GetCarInfo, GetDeviceInfo, SetCurrentTime, UseAuth } from './Index/utils';
|
||||
import { GetSyncData, InitializeTheCentralTable } from '../utils/table/Operation';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
|
||||
@ -495,7 +495,6 @@ struct Index {
|
||||
// this.fileHelper.createAlbum('2025-01-02')
|
||||
this.fileHelper.createAlbum('pz');
|
||||
this.fileHelper.createAlbum(date);
|
||||
|
||||
}
|
||||
|
||||
async initParams() {
|
||||
@ -508,7 +507,8 @@ struct Index {
|
||||
getTCP()
|
||||
this.carInfo = AppStorage.get('carInfo')
|
||||
this.deviceId = this.carInfo.carNo
|
||||
await setCurrentTime();
|
||||
// await setCurrentTime();
|
||||
await SetCurrentTime()
|
||||
this.timeInfo = AppStorage.get('timeInfo')
|
||||
const distanceClass = AppStorage.get('distanceClass') as boolean
|
||||
if (!distanceClass) {
|
||||
|
||||
@ -2,11 +2,20 @@ import common from "@ohos.app.ability.common";
|
||||
import FileUtil from "../../common/utils/File";
|
||||
import { GlobalConfig } from "../../config";
|
||||
import Prompt from "@system.prompt";
|
||||
import { CarConfigurationParamsType, ObtainCarExamInfoParams } from "../../model";
|
||||
import {
|
||||
ApiResponseType,
|
||||
BaseInfoType,
|
||||
CarConfigurationParamsType,
|
||||
ObtainCarExamInfoParams,
|
||||
ObtainCarExamInfoRspBody,
|
||||
TimeSynchronizationParams
|
||||
} from "../../model";
|
||||
import dayTs from "../../utils/Date";
|
||||
import { obtainCarExamInfo } from "../../api";
|
||||
import { obtainCarExamInfo, timeSynchronization } from "../../api";
|
||||
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
|
||||
import { BusinessError } from "@ohos.base";
|
||||
import App from "@system.app";
|
||||
import systemTime from "@ohos.systemTime";
|
||||
|
||||
//获取设备信息
|
||||
export async function GetDeviceInfo(context: common.UIAbilityContext): Promise<string> {
|
||||
@ -35,10 +44,9 @@ export async function GetCarInfo() {
|
||||
time: dayTs(date).format("YYYY-MM-DD HH:mm:ss"),
|
||||
deviceNo: AppStorage.get('deviceNo')
|
||||
};
|
||||
// TODO 待完善
|
||||
let res: ESObject = await obtainCarExamInfo(params)
|
||||
let res: ApiResponseType = await obtainCarExamInfo(params)
|
||||
if (res.obtainCarExamInfoRsp.body) {
|
||||
const carInfo: ESObject = res?.obtainCarExamInfoRsp?.body
|
||||
const carInfo: ObtainCarExamInfoRspBody = res?.obtainCarExamInfoRsp?.body
|
||||
carInfo.plateNo = decodeURIComponent(carInfo.plateNo)
|
||||
AppStorage.setOrCreate('carInfo', carInfo)
|
||||
}
|
||||
@ -68,4 +76,25 @@ export async function UseAuth(context: common.UIAbilityContext): Promise<boolean
|
||||
reject(false)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
//获取时间同步
|
||||
export async function SetCurrentTime(): Promise<void> {
|
||||
let deviceNo: string = AppStorage.get<string>('deviceNo');
|
||||
let baseInfo: BaseInfoType = AppStorage.get<BaseInfoType>('baseInfo')
|
||||
let params: TimeSynchronizationParams = {
|
||||
time: dayTs(new Date()).format("YYYY-MM-DD HH:mm:ss"),
|
||||
deviceNo,
|
||||
version: baseInfo.version,
|
||||
judgeVersion: baseInfo.judgeVersion
|
||||
}
|
||||
let res: ApiResponseType = await timeSynchronization(params);
|
||||
AppStorage.setOrCreate('timeInfo', res.timeSynchronizationRsp.body)
|
||||
let currentTime = res.timeSynchronizationRsp.head.time;
|
||||
let times = new Date(currentTime).getTime();
|
||||
try {
|
||||
await systemTime.setTime(times)
|
||||
} catch (error) {
|
||||
console.log('时间同步失败', error)
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,7 @@ import deviceManager from '@ohos.distributedHardware.deviceManager'
|
||||
import promptAction from '@ohos.promptAction'
|
||||
import FileUtil from '../common/utils/File'
|
||||
import common from '@ohos.app.ability.common'
|
||||
import { DeviceParamType, RegistrationDeviceNoRsp } from '../model'
|
||||
import { DeviceParamType, ApiResponseType } from '../model'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
@ -126,7 +126,7 @@ struct Index {
|
||||
fileUtil.addFile(`${folderPath}/deviceNo.txt`, JSON.stringify(param))
|
||||
AppStorage.setOrCreate('deviceNo', this.ip)
|
||||
// upDateTableByArray('DeviceInfoTable', [{ deviceId: this.ip }])
|
||||
registrationDeviceNo(param).then((res: RegistrationDeviceNoRsp) => {
|
||||
registrationDeviceNo(param).then((res: ApiResponseType) => {
|
||||
if (res.registrationDeviceNoRsp.head.resultCode == '0') {
|
||||
promptAction.showToast({
|
||||
message: decodeURIComponent(res.registrationDeviceNoRsp.head.resultMessage),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import libJudgeSdk from 'libJudgeSdk.so'
|
||||
import libJudgeSdk from "libjudgesdk.so"
|
||||
|
||||
// import libJudgeSdk from '@ohos.judgesdk'
|
||||
/**
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
import dayTs from "./Date";
|
||||
|
||||
enum timeType {
|
||||
fulltime = 1
|
||||
}
|
||||
|
||||
export function GetCurrentTime(type?: timeType): string {
|
||||
if (type === 1) {
|
||||
return dayTs().format("YYYYMMDDHHmmss")
|
||||
} else {
|
||||
return dayTs().format("YYYY-MM-DD HH:mm:ss")
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,7 @@ interface DateData {
|
||||
getMinutes: () => number;
|
||||
getSeconds: () => number;
|
||||
getDay: () => number;
|
||||
getMilliseconds: () => number;
|
||||
}
|
||||
|
||||
// 时间处理相关函数集合dayTs("2024-02-21 17:13:00").format("YYYY-MM-DD HH:mm:ss")
|
||||
@ -27,23 +28,24 @@ class DayTs {
|
||||
}
|
||||
}
|
||||
|
||||
private static _paddingZero(num: number): string {
|
||||
return `${num}`.padStart(2, '0')
|
||||
private static _paddingZero(num: number, length: number = 2): string {
|
||||
return `${num}`.padStart(length, '0');
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
public format(formatter: string = 'yyyy/MM/dd HH:mm:ss') {
|
||||
const day = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
|
||||
const day = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
|
||||
const obj: Record<string, string | number | ((dateData: DateData) => string | number)> = {
|
||||
'Y{4}': (dateData: DateData) => dateData.getFullYear(),
|
||||
'y+': (dateData: DateData) => dateData.getFullYear(),
|
||||
'M{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getMonth() + 1),
|
||||
"D{2}": (dateData: DateData) => DayTs._paddingZero(dateData.getDate()),
|
||||
'D{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getDate()),
|
||||
'd{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getDate()),
|
||||
'H{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getHours()),
|
||||
'h{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getHours() % 12),
|
||||
'm{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getMinutes()),
|
||||
's{2}': (dateData: DateData) => DayTs._paddingZero(dateData.getSeconds()),
|
||||
'S{3}': (dateData: DateData) => DayTs._paddingZero(dateData.getMilliseconds(), 3), // 添加毫秒支持
|
||||
'M': (dateData: DateData) => dateData.getMonth() + 1,
|
||||
'd': (dateData: DateData) => dateData.getDate(),
|
||||
'H': (dateData: DateData) => dateData.getHours(),
|
||||
@ -51,8 +53,9 @@ class DayTs {
|
||||
'm': (dateData: DateData) => dateData.getMinutes(),
|
||||
's': (dateData: DateData) => dateData.getSeconds(),
|
||||
'CW': (dateData: DateData) => day[dateData.getDay()],
|
||||
'W': (dateData: DateData) => dateData.getDay()
|
||||
'W': (dateData: DateData) => dateData.getDay(),
|
||||
};
|
||||
|
||||
const objEntries = Object.entries(obj);
|
||||
for (let i = 0; i < objEntries.length; i++) {
|
||||
const key = objEntries[i][0];
|
||||
@ -64,7 +67,7 @@ class DayTs {
|
||||
}
|
||||
}
|
||||
|
||||
return formatter
|
||||
return formatter;
|
||||
}
|
||||
|
||||
// 获取时间戳
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user