接口对接
This commit is contained in:
		
							parent
							
								
									d2cf99d6c9
								
							
						
					
					
						commit
						ec7c45bb29
					
				
							
								
								
									
										3
									
								
								entry/src/main/ets/api/typings.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								entry/src/main/ets/api/typings.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -246,6 +246,7 @@ declare namespace API { | ||||
|     orderByColumn?: string; | ||||
|     pageNum?: number; | ||||
|     pageSize?: number; | ||||
|     serialNumber?: string | ||||
|     reasonable?: boolean; | ||||
|     /** 查验结果 */ | ||||
|     results?: string; | ||||
| @ -688,7 +689,7 @@ declare namespace API { | ||||
|     /** 其他移动:轮胎左侧转向、备胎移出等 */ | ||||
|     otherMove?: string; | ||||
|     /** padId */ | ||||
|     padId?: number; | ||||
|     padId?: string; | ||||
|     pageNum?: number; | ||||
|     pageSize?: number; | ||||
|     /** 铭牌照片 */ | ||||
|  | ||||
| @ -80,20 +80,26 @@ struct Index { | ||||
| 
 | ||||
|     let deviceId = await getDeviceId() | ||||
| 
 | ||||
|     this.controller.open() | ||||
| 
 | ||||
|     padLoginUsingPost({ | ||||
|       username: this.account, | ||||
|       password: this.password, | ||||
|       imei: deviceId | ||||
|     }).then((res) => { | ||||
|       AppStorage.setOrCreate("padId", res.data?.padId!) | ||||
|       router.pushUrl({ | ||||
|         url: "pages/home/Index" | ||||
|       }) | ||||
|     }).finally(() => { | ||||
|       this.controller.close() | ||||
|     router.pushUrl({ | ||||
|       // url: "pages/home/Index" | ||||
|       url: "pages/vehicle/Add" | ||||
|     }) | ||||
| 
 | ||||
|     // this.controller.open() | ||||
|     // | ||||
|     // | ||||
|     // padLoginUsingPost({ | ||||
|     //   username: this.account, | ||||
|     //   password: this.password, | ||||
|     //   imei: deviceId | ||||
|     // }).then((res) => { | ||||
|     //   AppStorage.setOrCreate("padId", res.data?.padId!) | ||||
|     //   router.pushUrl({ | ||||
|     //     url: "pages/home/Index" | ||||
|     //   }) | ||||
|     // }).finally(() => { | ||||
|     //   this.controller.close() | ||||
|     // }) | ||||
|   } | ||||
| 
 | ||||
|   build() { | ||||
|  | ||||
| @ -2,6 +2,7 @@ import { promptAction, router } from '@kit.ArkUI' | ||||
| import { saveVinPositionUsingPost } from '../../api/vehicleCollectionController' | ||||
| import { Option } from '../../typings/Common' | ||||
| import { CusButton } from '../components/button/Index' | ||||
| import { CusInput } from '../components/input/Index' | ||||
| import { Layout } from '../components/layout/Index' | ||||
| import { Title } from '../components/title/Index' | ||||
| import { Card } from './component/Card' | ||||
| @ -115,9 +116,35 @@ struct Add { | ||||
|   @State picture3: string = "" | ||||
|   @State picture4: string = "" | ||||
|   @State otherInput: string = "" | ||||
|   @State factoryName: string = '' | ||||
|   @State brandName: string = '' | ||||
|   @State model: string = '' | ||||
|   @State year: string = '' | ||||
|   @State month: string = '' | ||||
| 
 | ||||
|   aboutToAppear(): void { | ||||
|     this.setup() | ||||
|     let data: API.InspectRecordResultRsp = router.getParams() | ||||
|     if (data?.factoryName) { | ||||
|       this.base[0].value = data?.factoryName || "" | ||||
|       this.base[0].init = true | ||||
|     } | ||||
|     if (data?.brandName) { | ||||
|       this.base[1].value = data?.brandName || "" | ||||
|       this.base[1].init = true | ||||
|     } | ||||
|     if (data?.model) { | ||||
|       this.base[2].value = data?.model || "" | ||||
|       this.base[2].init = true | ||||
|     } | ||||
|     if (data?.factoryName) { | ||||
|       this.base[3].value = data?.factoryName || "" | ||||
|       this.base[3].init = true | ||||
|     } | ||||
|     if (data?.factoryName) { | ||||
|       this.base[4].value = data?.factoryName || "" | ||||
|       this.base[4].init = true | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   setup() { | ||||
| @ -181,7 +208,6 @@ struct Add { | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     if (!this.vehicleIdentityPosition) { | ||||
|       promptAction.showToast({ | ||||
|         message: "请选择铭牌位置" | ||||
| @ -226,11 +252,11 @@ struct Add { | ||||
| 
 | ||||
| 
 | ||||
|     const data: API.VehicleCollectionReq = { | ||||
|       brandName: this.base[1].value, | ||||
|       factoryName: this.base[0].value, | ||||
|       model: this.base[2].value, | ||||
|       year: this.base[3].value, | ||||
|       month: this.base[4].value, | ||||
|       factoryName: this.factoryName ?? this.base[0].value, | ||||
|       brandName: this.brandName ?? this.base[1].value, | ||||
|       model: this.model ?? this.base[2].value, | ||||
|       year: this.year ?? this.base[3].value, | ||||
|       month: this.month ?? this.base[4].value, | ||||
|       platePhotoUrl: "", | ||||
| 
 | ||||
|       platePosition: this.nameplatePosition, | ||||
| @ -273,21 +299,35 @@ struct Add { | ||||
|           Scroll() { | ||||
|             Column() { | ||||
|               Flex({ justifyContent: FlexAlign.SpaceBetween }) { | ||||
|                 ForEach(this.base, (item: Option) => { | ||||
|                 ForEach(this.base, (item: Option, index: number) => { | ||||
|                   Row() { | ||||
|                     Text(item.label).fontSize(20).fontColor(0x1D2B80).margin({ right: 12 }) | ||||
|                     Text(item.value) | ||||
|                       .fontSize(20) | ||||
|                       .fontColor(0x1D2B80) | ||||
|                       .backgroundColor(0xeeeeee) | ||||
|                       .border({ width: 1, color: 0xe5e5e5, radius: 5 }) | ||||
|                       .padding({ | ||||
|                         left: 12, | ||||
|                         top: 6, | ||||
|                         right: 12, | ||||
|                         bottom: 6 | ||||
|                       }) | ||||
|                   } | ||||
|                     if (item.init) { | ||||
|                       Text(item.value) | ||||
|                         .fontSize(20) | ||||
|                         .fontColor(0x1D2B80) | ||||
|                         .backgroundColor(0xeeeeee) | ||||
|                         .border({ width: 1, color: 0xe5e5e5, radius: 5 }) | ||||
|                         .padding({ | ||||
|                           left: 12, | ||||
|                           top: 6, | ||||
|                           right: 12, | ||||
|                           bottom: 6 | ||||
|                         }) | ||||
|                     } else { | ||||
|                       if (index === 0) { | ||||
|                         CusInput({ value: this.factoryName }).height(32).layoutWeight(1) | ||||
|                       } else if (index === 1) { | ||||
|                         CusInput({ value: this.brandName }).height(32).layoutWeight(1) | ||||
|                       } else if (index === 2) { | ||||
|                         CusInput({ value: this.model }).height(32).layoutWeight(1) | ||||
|                       } else if (index === 3) { | ||||
|                         CusInput({ value: this.year }).height(32).layoutWeight(1) | ||||
|                       } else if (index === 4) { | ||||
|                         CusInput({ value: this.month }).height(32).layoutWeight(1) | ||||
|                       } | ||||
|                     } | ||||
|                   }.layoutWeight(1).padding({ left: 12 }) | ||||
|                 }) | ||||
|               }.margin({ bottom: 18 }) | ||||
| 
 | ||||
|  | ||||
| @ -12,23 +12,25 @@ import { getInspectResultListUsingPost } from '../../api' | ||||
| struct Vehicle { | ||||
|   @State columns: Array<Column> = [] | ||||
|   @State data: Array<API.InspectRecordResultRsp> = [] | ||||
|   @State total: number = 500 | ||||
|   @State total: number = 0 | ||||
|   @State loading: boolean = false | ||||
|   @State date: string[] = [] | ||||
|   @State line: string = "" | ||||
|   @State state: string = "" | ||||
|   @State step: string = "" | ||||
|   @State status: string = "" | ||||
|   @State keyword: string = "" | ||||
|   @State serialNumber: string = "" | ||||
|   @State name: string = "" | ||||
|   @State currentPage: number = 1 | ||||
|   private pageSize: number = 10 | ||||
|   private pageSizes: number[] = [10, 20, 30, 50] | ||||
| 
 | ||||
|   @Builder | ||||
|   buildOperate(_row: API.InspectRecordResultRsp) { | ||||
|   buildOperate(row: API.InspectRecordResultRsp) { | ||||
|     Image($rawfile("images/detail.png")).objectFit(ImageFit.Contain).width(80).height(30).onClick(() => { | ||||
|       router.pushUrl({ | ||||
|         url: "pages/vehicle/Add" | ||||
|         url: "pages/vehicle/Add", | ||||
|         params: row | ||||
|       }) | ||||
|     }) | ||||
|   } | ||||
| @ -44,12 +46,12 @@ struct Vehicle { | ||||
|       { title: "查验日期", prop: "createTime", width: 1, }, | ||||
|       { title: "流水号", prop: "serialNumber", width: 1, }, | ||||
|       { title: "业务类型", prop: "businessType", width: 1, }, | ||||
|       { title: "号牌种类", prop: "vin", width: 1, }, | ||||
|       // { title: "号牌种类", prop: "vin", width: 1, }, | ||||
|       { title: "车辆品牌", prop: "brandName", width: 1, }, | ||||
|       { title: "型号", prop: "model", width: 1, }, | ||||
|       // { title: "生产厂家", prop: "factoryName", width: 1.5, }, | ||||
|       // { title: "生产年月", prop: "step", width: 1, }, | ||||
|       // { title: "车主姓名", prop: "step", width: 1, }, | ||||
|       { title: "生产厂家", prop: "factoryName", width: 1.5, }, | ||||
|       { title: "生产年月", prop: "step", width: 1, }, | ||||
|       { title: "车主姓名", prop: "step", width: 1, }, | ||||
|       { | ||||
|         title: "操作", | ||||
|         prop: "", | ||||
| @ -59,7 +61,6 @@ struct Vehicle { | ||||
|         } | ||||
|       }, | ||||
|     ] | ||||
|     this.total = 500 | ||||
|     this.getData() | ||||
|   } | ||||
| 
 | ||||
| @ -70,6 +71,7 @@ struct Vehicle { | ||||
|       inspectEndDate: this.date[1], | ||||
|       pageNum: this.currentPage, | ||||
|       pageSize: this.pageSize, | ||||
|       serialNumber: this.serialNumber, | ||||
|       unMatch: "1" | ||||
|     }).then(res => { | ||||
|       this.data = res.rows || [] | ||||
| @ -87,7 +89,8 @@ struct Vehicle { | ||||
|     this.state = "" | ||||
|     this.step = "" | ||||
|     this.status = "" | ||||
|     this.keyword = "" | ||||
|     this.serialNumber = "" | ||||
|     this.name = "" | ||||
|   } | ||||
| 
 | ||||
|   build() { | ||||
| @ -104,8 +107,8 @@ struct Vehicle { | ||||
| 
 | ||||
|           Row() { | ||||
|             DateRangePicker({ placeHolder: "日期", value: this.date }).margin({ right: 12 }).layoutWeight(2) | ||||
|             CusInput({ value: this.keyword, placeHolder: "流水号" }).margin({ right: 12 }).layoutWeight(1) | ||||
|             CusInput({ value: this.keyword, placeHolder: "车主姓名" }).margin({ right: 12 }).layoutWeight(1) | ||||
|             CusInput({ value: this.serialNumber, placeHolder: "流水号" }).margin({ right: 12 }).layoutWeight(2) | ||||
|             CusInput({ value: this.name, placeHolder: "车主姓名" }).margin({ right: 12 }).layoutWeight(1) | ||||
|             Row().layoutWeight(2) | ||||
|             CusButton({ | ||||
|               normalImage: $rawfile("images/search.png"), | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| export interface Option<T = string> { | ||||
|   label: string | ||||
|   value: T | ||||
|   init?: boolean | ||||
| } | ||||
| @ -1,18 +1,52 @@ | ||||
| import Logger from './Logger'; | ||||
| import { TaskPool } from './TaskPool'; | ||||
| import { WebsocketClient } from './WebsocketUtils'; | ||||
| import { util } from '@kit.ArkTS'; | ||||
| 
 | ||||
| const Tag = "CommandService" | ||||
| 
 | ||||
| interface Message { | ||||
|   type: string | ||||
| interface Message<T = Object> { | ||||
|   type: CommandType | ||||
|   reqCode: string | ||||
|   body: object | ||||
|   body: T | ||||
| } | ||||
| 
 | ||||
| interface HandleAlarmBody { | ||||
|   alarmId: string | ||||
|   handleInfo: string | ||||
| } | ||||
| 
 | ||||
| interface CommandBody { | ||||
|   lineId: string | ||||
|   code: string | ||||
|   name: string | ||||
| } | ||||
| 
 | ||||
| interface ResponseMessage { | ||||
|   code: string | ||||
|   msg: string | ||||
| } | ||||
| 
 | ||||
| enum CommandType { | ||||
|   HandleAlarm = "handleAlarm", | ||||
|   PostCmd = "PostCmd" | ||||
| } | ||||
| 
 | ||||
| enum CommandCode { | ||||
|   GetHomePosition = 'getHomePosition', | ||||
|   ToHomePosition = 'toHomePosition', | ||||
|   GetChargePosition = 'getChargePosition', | ||||
|   ToChargePosition = 'toChargePosition', | ||||
|   GetScanPosition = 'getScanPosition', | ||||
|   ToScanPosition = 'toScanPosition', | ||||
| } | ||||
| 
 | ||||
| export class CommandService { | ||||
|   private service?: WebsocketClient | ||||
|   private taskPool: TaskPool<boolean> = new TaskPool() | ||||
|   private static instance: CommandService | ||||
|   private tick: number = -1 | ||||
|   private commandCallback: Map<string, Function> = new Map() | ||||
| 
 | ||||
|   constructor(url: string) { | ||||
|     if (!CommandService.instance) { | ||||
| @ -22,27 +56,41 @@ export class CommandService { | ||||
|     return CommandService.instance | ||||
|   } | ||||
| 
 | ||||
|   deal(message: string) { | ||||
|     return message | ||||
|   private deal(message: string) { | ||||
|     if (message === "pong") { | ||||
|       Logger.info("心跳回应") | ||||
|       return "" | ||||
|     } else { | ||||
|       try { | ||||
|         let response: Message<ResponseMessage> = JSON.parse(message) | ||||
|         if (response.type === CommandType.PostCmd) { | ||||
|           this.commandCallback.get(response.reqCode)?.(response.body) | ||||
|           this.commandCallback.delete(response.reqCode) | ||||
|         } | ||||
|         return message | ||||
|       } catch (e) { | ||||
|         Logger.error(Tag, "解析报文出错", JSON.stringify(e)) | ||||
|         return "" | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   init() { | ||||
|     return this.service!.connect() | ||||
|   } | ||||
| 
 | ||||
|   subscribe(cb: Function) { | ||||
|     this.service!.subscribe(cb) | ||||
|   } | ||||
| 
 | ||||
|   unsubscribe(cb: Function) { | ||||
|     this.service!.unsubscribe(cb) | ||||
|   } | ||||
| 
 | ||||
|   send(message: Message) { | ||||
|     return new Promise<void>((resolve, reject) => { | ||||
|   private send(message: Message) { | ||||
|     return new Promise<void | ResponseMessage>((resolve, reject) => { | ||||
|       this.taskPool.add({ | ||||
|         execute: () => { | ||||
|           return this.service!.send(JSON.stringify(message)) | ||||
|           if (message.type === CommandType.PostCmd) { | ||||
|             return new Promise<boolean>((_resolve, _reject) => { | ||||
|               this.service!.send(JSON.stringify(message)).then(() => { | ||||
|                 this.commandCallback.set(message.reqCode, (res: ResponseMessage) => { | ||||
|                   resolve(res) | ||||
|                 }) | ||||
|                 _resolve(true) | ||||
|               }).catch(_reject) | ||||
|             }) | ||||
|           } else { | ||||
|             return this.service!.send(JSON.stringify(message)) | ||||
|           } | ||||
|         }, | ||||
|         repair: (): Promise<void> => { | ||||
|           return this.service!.reconnect(); | ||||
| @ -58,9 +106,54 @@ export class CommandService { | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   init() { | ||||
|     return new Promise<void>((resolve, reject) => { | ||||
|       this.service!.connect().then(() => { | ||||
|         this.tick = setInterval(() => { | ||||
|           this.service?.send("ping") | ||||
|         }, 1000 * 15) | ||||
|         resolve() | ||||
|       }).catch(reject) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   subscribe(cb: Function) { | ||||
|     this.service!.subscribe(cb) | ||||
|   } | ||||
| 
 | ||||
|   unsubscribe(cb: Function) { | ||||
|     this.service!.unsubscribe(cb) | ||||
|   } | ||||
| 
 | ||||
|   close(): Promise<boolean> { | ||||
|     clearInterval(this.tick) | ||||
|     return this.service!.close() | ||||
|   } | ||||
| 
 | ||||
|   submitAlarm(alarmId: string, handleInfo: string): Promise<void> { | ||||
|     let handleBody: HandleAlarmBody = { | ||||
|       alarmId, | ||||
|       handleInfo | ||||
|     } | ||||
|     return this.send({ | ||||
|       type: CommandType.HandleAlarm, | ||||
|       reqCode: util.generateRandomUUID(true), | ||||
|       body: handleBody | ||||
|     }) as Promise<void> | ||||
|   } | ||||
| 
 | ||||
|   submitCommand(lineId: string, code: CommandCode, name: string): Promise<ResponseMessage> { | ||||
|     let commandBody: CommandBody = { | ||||
|       lineId, | ||||
|       code, | ||||
|       name | ||||
|     } | ||||
|     return this.send({ | ||||
|       type: CommandType.PostCmd, | ||||
|       reqCode: util.generateRandomUUID(true), | ||||
|       body: commandBody | ||||
|     }) as Promise<ResponseMessage> | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| export const commandService = | ||||
|  | ||||
| @ -164,5 +164,5 @@ export function readLog(context: common.UIAbilityContext) { | ||||
| 
 | ||||
| export function uploadLog(context: common.UIAbilityContext) { | ||||
|   let path = context.filesDir + '/logs/2025_09_25/14_25_31.331.log' | ||||
|   uploadFile(context, "http://192.168.67.190:8088/common/upload", path) | ||||
|   uploadFile(context, path) | ||||
| } | ||||
| @ -40,6 +40,8 @@ export async function request<T>( | ||||
| ): Promise<T> { | ||||
|   const httpRequest = http.createHttp(); | ||||
|   return new Promise((resolve, reject) => { | ||||
|     Logger.info(Tag, | ||||
|       `开始请求接口 ${url}, query: ${JSON.stringify(config.params)}, data: ${JSON.stringify(config.data)}`) | ||||
|     httpRequest.request(BaseUrl + url, | ||||
|       { | ||||
|         method: config.method, | ||||
| @ -48,29 +50,21 @@ export async function request<T>( | ||||
|         }, | ||||
|         extraData: config.method == "POST" ? config.data : config.params, | ||||
|         expectDataType: http.HttpDataType.OBJECT, | ||||
|         connectTimeout: 60000, //超时时间 | ||||
|         connectTimeout: 1000 * 6, //超时时间 | ||||
|       }).then(async (data) => { | ||||
|       let result = data.result as Response | ||||
|       Logger.info(Tag, `request url ${url} result: `, JSON.stringify(data.result)) | ||||
|       Logger.info(Tag, `请求接口 ${url} 成功, 请求结果: `, JSON.stringify(data.result)) | ||||
|       if (result.code === 200) { | ||||
|         if (new RegExp("robotLogin").test(url)) { | ||||
|           try { | ||||
|             token = result.data['token'] | ||||
|           } catch (err) { | ||||
|             let e: BusinessError = err as BusinessError; | ||||
|             Logger.error(Tag, JSON.stringify(e)) | ||||
|           } | ||||
|         } | ||||
|         resolve(data.result as T) | ||||
|       } else { | ||||
|         Logger.error(Tag, "error message receive: ", url, result.msg) | ||||
|         Logger.error(Tag, `请求接口 ${url} 失败, 失败原因: `, result.msg) | ||||
|         promptAction.showToast({ | ||||
|           message: result.msg | ||||
|         }) | ||||
|         reject(result.msg) | ||||
|       } | ||||
|     }).catch((err: BusinessError) => { | ||||
|       Logger.error(Tag, "error request url: ", BaseUrl + url, err.message) | ||||
|       Logger.error(Tag, `请求接口 ${url} 异常, 异常原因: `, JSON.stringify(err)) | ||||
|       promptAction.showToast({ | ||||
|         message: '网络异常' | ||||
|       }) | ||||
| @ -82,7 +76,7 @@ export async function request<T>( | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| export async function uploadFile(context: common.UIAbilityContext, url: string, path: string) { | ||||
| export async function uploadFile(context: common.UIAbilityContext, path: string) { | ||||
|   if (!fs.accessSync(path)) { | ||||
|     Logger.error(Tag, "UPLOAD FILE ERROR: ", "上传文件不存在") | ||||
|     return Promise.reject("上传文件不存在") | ||||
| @ -95,7 +89,7 @@ export async function uploadFile(context: common.UIAbilityContext, url: string, | ||||
|   try { | ||||
|     return new Promise<void>((resolve, reject) => { | ||||
|       sysRequest.uploadFile(context, { | ||||
|         url: BaseUrl + url, | ||||
|         url: BaseUrl + "/car-inspection-rest/device/uploadPhoto.do", | ||||
|         header: { 'Accept': '*/*', 'Content-Type': 'multipart/form-data' }, | ||||
|         method: http.RequestMethod.POST, | ||||
|         files: [ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user