接口对接

This commit is contained in:
lixiao 2025-09-28 17:37:28 +08:00
parent d2cf99d6c9
commit ec7c45bb29
8 changed files with 218 additions and 80 deletions

View File

@ -246,6 +246,7 @@ declare namespace API {
orderByColumn?: string; orderByColumn?: string;
pageNum?: number; pageNum?: number;
pageSize?: number; pageSize?: number;
serialNumber?: string
reasonable?: boolean; reasonable?: boolean;
/** 查验结果 */ /** 查验结果 */
results?: string; results?: string;
@ -688,7 +689,7 @@ declare namespace API {
/** 其他移动:轮胎左侧转向、备胎移出等 */ /** 其他移动:轮胎左侧转向、备胎移出等 */
otherMove?: string; otherMove?: string;
/** padId */ /** padId */
padId?: number; padId?: string;
pageNum?: number; pageNum?: number;
pageSize?: number; pageSize?: number;
/** 铭牌照片 */ /** 铭牌照片 */

View File

@ -80,20 +80,26 @@ struct Index {
let deviceId = await getDeviceId() let deviceId = await getDeviceId()
this.controller.open() router.pushUrl({
// url: "pages/home/Index"
padLoginUsingPost({ url: "pages/vehicle/Add"
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()
}) })
// 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() { build() {

View File

@ -2,6 +2,7 @@ import { promptAction, router } from '@kit.ArkUI'
import { saveVinPositionUsingPost } from '../../api/vehicleCollectionController' import { saveVinPositionUsingPost } from '../../api/vehicleCollectionController'
import { Option } from '../../typings/Common' import { Option } from '../../typings/Common'
import { CusButton } from '../components/button/Index' import { CusButton } from '../components/button/Index'
import { CusInput } from '../components/input/Index'
import { Layout } from '../components/layout/Index' import { Layout } from '../components/layout/Index'
import { Title } from '../components/title/Index' import { Title } from '../components/title/Index'
import { Card } from './component/Card' import { Card } from './component/Card'
@ -115,9 +116,35 @@ struct Add {
@State picture3: string = "" @State picture3: string = ""
@State picture4: string = "" @State picture4: string = ""
@State otherInput: string = "" @State otherInput: string = ""
@State factoryName: string = ''
@State brandName: string = ''
@State model: string = ''
@State year: string = ''
@State month: string = ''
aboutToAppear(): void { aboutToAppear(): void {
this.setup() 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() { setup() {
@ -181,7 +208,6 @@ struct Add {
return; return;
} }
if (!this.vehicleIdentityPosition) { if (!this.vehicleIdentityPosition) {
promptAction.showToast({ promptAction.showToast({
message: "请选择铭牌位置" message: "请选择铭牌位置"
@ -226,11 +252,11 @@ struct Add {
const data: API.VehicleCollectionReq = { const data: API.VehicleCollectionReq = {
brandName: this.base[1].value, factoryName: this.factoryName ?? this.base[0].value,
factoryName: this.base[0].value, brandName: this.brandName ?? this.base[1].value,
model: this.base[2].value, model: this.model ?? this.base[2].value,
year: this.base[3].value, year: this.year ?? this.base[3].value,
month: this.base[4].value, month: this.month ?? this.base[4].value,
platePhotoUrl: "", platePhotoUrl: "",
platePosition: this.nameplatePosition, platePosition: this.nameplatePosition,
@ -273,21 +299,35 @@ struct Add {
Scroll() { Scroll() {
Column() { Column() {
Flex({ justifyContent: FlexAlign.SpaceBetween }) { Flex({ justifyContent: FlexAlign.SpaceBetween }) {
ForEach(this.base, (item: Option) => { ForEach(this.base, (item: Option, index: number) => {
Row() { Row() {
Text(item.label).fontSize(20).fontColor(0x1D2B80).margin({ right: 12 }) Text(item.label).fontSize(20).fontColor(0x1D2B80).margin({ right: 12 })
Text(item.value) if (item.init) {
.fontSize(20) Text(item.value)
.fontColor(0x1D2B80) .fontSize(20)
.backgroundColor(0xeeeeee) .fontColor(0x1D2B80)
.border({ width: 1, color: 0xe5e5e5, radius: 5 }) .backgroundColor(0xeeeeee)
.padding({ .border({ width: 1, color: 0xe5e5e5, radius: 5 })
left: 12, .padding({
top: 6, left: 12,
right: 12, top: 6,
bottom: 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 }) }.margin({ bottom: 18 })

View File

@ -12,23 +12,25 @@ import { getInspectResultListUsingPost } from '../../api'
struct Vehicle { struct Vehicle {
@State columns: Array<Column> = [] @State columns: Array<Column> = []
@State data: Array<API.InspectRecordResultRsp> = [] @State data: Array<API.InspectRecordResultRsp> = []
@State total: number = 500 @State total: number = 0
@State loading: boolean = false @State loading: boolean = false
@State date: string[] = [] @State date: string[] = []
@State line: string = "" @State line: string = ""
@State state: string = "" @State state: string = ""
@State step: string = "" @State step: string = ""
@State status: string = "" @State status: string = ""
@State keyword: string = "" @State serialNumber: string = ""
@State name: string = ""
@State currentPage: number = 1 @State currentPage: number = 1
private pageSize: number = 10 private pageSize: number = 10
private pageSizes: number[] = [10, 20, 30, 50] private pageSizes: number[] = [10, 20, 30, 50]
@Builder @Builder
buildOperate(_row: API.InspectRecordResultRsp) { buildOperate(row: API.InspectRecordResultRsp) {
Image($rawfile("images/detail.png")).objectFit(ImageFit.Contain).width(80).height(30).onClick(() => { Image($rawfile("images/detail.png")).objectFit(ImageFit.Contain).width(80).height(30).onClick(() => {
router.pushUrl({ 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: "createTime", width: 1, },
{ title: "流水号", prop: "serialNumber", width: 1, }, { title: "流水号", prop: "serialNumber", width: 1, },
{ title: "业务类型", prop: "businessType", width: 1, }, { title: "业务类型", prop: "businessType", width: 1, },
{ title: "号牌种类", prop: "vin", width: 1, }, // { title: "号牌种类", prop: "vin", width: 1, },
{ title: "车辆品牌", prop: "brandName", width: 1, }, { title: "车辆品牌", prop: "brandName", width: 1, },
{ title: "型号", prop: "model", width: 1, }, { title: "型号", prop: "model", width: 1, },
// { title: "生产厂家", prop: "factoryName", width: 1.5, }, { title: "生产厂家", prop: "factoryName", width: 1.5, },
// { title: "生产年月", prop: "step", width: 1, }, { title: "生产年月", prop: "step", width: 1, },
// { title: "车主姓名", prop: "step", width: 1, }, { title: "车主姓名", prop: "step", width: 1, },
{ {
title: "操作", title: "操作",
prop: "", prop: "",
@ -59,7 +61,6 @@ struct Vehicle {
} }
}, },
] ]
this.total = 500
this.getData() this.getData()
} }
@ -70,6 +71,7 @@ struct Vehicle {
inspectEndDate: this.date[1], inspectEndDate: this.date[1],
pageNum: this.currentPage, pageNum: this.currentPage,
pageSize: this.pageSize, pageSize: this.pageSize,
serialNumber: this.serialNumber,
unMatch: "1" unMatch: "1"
}).then(res => { }).then(res => {
this.data = res.rows || [] this.data = res.rows || []
@ -87,7 +89,8 @@ struct Vehicle {
this.state = "" this.state = ""
this.step = "" this.step = ""
this.status = "" this.status = ""
this.keyword = "" this.serialNumber = ""
this.name = ""
} }
build() { build() {
@ -104,8 +107,8 @@ struct Vehicle {
Row() { Row() {
DateRangePicker({ placeHolder: "日期", value: this.date }).margin({ right: 12 }).layoutWeight(2) DateRangePicker({ placeHolder: "日期", value: this.date }).margin({ right: 12 }).layoutWeight(2)
CusInput({ value: this.keyword, placeHolder: "流水号" }).margin({ right: 12 }).layoutWeight(1) CusInput({ value: this.serialNumber, placeHolder: "流水号" }).margin({ right: 12 }).layoutWeight(2)
CusInput({ value: this.keyword, placeHolder: "车主姓名" }).margin({ right: 12 }).layoutWeight(1) CusInput({ value: this.name, placeHolder: "车主姓名" }).margin({ right: 12 }).layoutWeight(1)
Row().layoutWeight(2) Row().layoutWeight(2)
CusButton({ CusButton({
normalImage: $rawfile("images/search.png"), normalImage: $rawfile("images/search.png"),

View File

@ -1,4 +1,5 @@
export interface Option<T = string> { export interface Option<T = string> {
label: string label: string
value: T value: T
init?: boolean
} }

View File

@ -1,18 +1,52 @@
import Logger from './Logger';
import { TaskPool } from './TaskPool'; import { TaskPool } from './TaskPool';
import { WebsocketClient } from './WebsocketUtils'; import { WebsocketClient } from './WebsocketUtils';
import { util } from '@kit.ArkTS';
const Tag = "CommandService" const Tag = "CommandService"
interface Message { interface Message<T = Object> {
type: string type: CommandType
reqCode: string 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 { export class CommandService {
private service?: WebsocketClient private service?: WebsocketClient
private taskPool: TaskPool<boolean> = new TaskPool() private taskPool: TaskPool<boolean> = new TaskPool()
private static instance: CommandService private static instance: CommandService
private tick: number = -1
private commandCallback: Map<string, Function> = new Map()
constructor(url: string) { constructor(url: string) {
if (!CommandService.instance) { if (!CommandService.instance) {
@ -22,27 +56,41 @@ export class CommandService {
return CommandService.instance return CommandService.instance
} }
deal(message: string) { private deal(message: string) {
return message 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() { private send(message: Message) {
return this.service!.connect() return new Promise<void | ResponseMessage>((resolve, reject) => {
}
subscribe(cb: Function) {
this.service!.subscribe(cb)
}
unsubscribe(cb: Function) {
this.service!.unsubscribe(cb)
}
send(message: Message) {
return new Promise<void>((resolve, reject) => {
this.taskPool.add({ this.taskPool.add({
execute: () => { 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> => { repair: (): Promise<void> => {
return this.service!.reconnect(); 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> { close(): Promise<boolean> {
clearInterval(this.tick)
return this.service!.close() 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 = export const commandService =

View File

@ -164,5 +164,5 @@ export function readLog(context: common.UIAbilityContext) {
export function uploadLog(context: common.UIAbilityContext) { export function uploadLog(context: common.UIAbilityContext) {
let path = context.filesDir + '/logs/2025_09_25/14_25_31.331.log' 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)
} }

View File

@ -40,6 +40,8 @@ export async function request<T>(
): Promise<T> { ): Promise<T> {
const httpRequest = http.createHttp(); const httpRequest = http.createHttp();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
Logger.info(Tag,
`开始请求接口 ${url}, query: ${JSON.stringify(config.params)}, data: ${JSON.stringify(config.data)}`)
httpRequest.request(BaseUrl + url, httpRequest.request(BaseUrl + url,
{ {
method: config.method, method: config.method,
@ -48,29 +50,21 @@ export async function request<T>(
}, },
extraData: config.method == "POST" ? config.data : config.params, extraData: config.method == "POST" ? config.data : config.params,
expectDataType: http.HttpDataType.OBJECT, expectDataType: http.HttpDataType.OBJECT,
connectTimeout: 60000, //超时时间 connectTimeout: 1000 * 6, //超时时间
}).then(async (data) => { }).then(async (data) => {
let result = data.result as Response 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 (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) resolve(data.result as T)
} else { } else {
Logger.error(Tag, "error message receive: ", url, result.msg) Logger.error(Tag, `请求接口 ${url} 失败, 失败原因: `, result.msg)
promptAction.showToast({ promptAction.showToast({
message: result.msg message: result.msg
}) })
reject(result.msg) reject(result.msg)
} }
}).catch((err: BusinessError) => { }).catch((err: BusinessError) => {
Logger.error(Tag, "error request url: ", BaseUrl + url, err.message) Logger.error(Tag, `请求接口 ${url} 异常, 异常原因: `, JSON.stringify(err))
promptAction.showToast({ promptAction.showToast({
message: '网络异常' 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)) { if (!fs.accessSync(path)) {
Logger.error(Tag, "UPLOAD FILE ERROR: ", "上传文件不存在") Logger.error(Tag, "UPLOAD FILE ERROR: ", "上传文件不存在")
return Promise.reject("上传文件不存在") return Promise.reject("上传文件不存在")
@ -95,7 +89,7 @@ export async function uploadFile(context: common.UIAbilityContext, url: string,
try { try {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
sysRequest.uploadFile(context, { sysRequest.uploadFile(context, {
url: BaseUrl + url, url: BaseUrl + "/car-inspection-rest/device/uploadPhoto.do",
header: { 'Accept': '*/*', 'Content-Type': 'multipart/form-data' }, header: { 'Accept': '*/*', 'Content-Type': 'multipart/form-data' },
method: http.RequestMethod.POST, method: http.RequestMethod.POST,
files: [ files: [