268 lines
8.5 KiB
Plaintext
268 lines
8.5 KiB
Plaintext
import request from '../utils/Request';
|
|
import writeObjectOutNew from './judgeNew';
|
|
import http from '@ohos.net.http';
|
|
import { MASYSSETTableType, RegulatoryInterfaceParams } from '../model';
|
|
import { GetSyncData } from '../utils/table/Operation';
|
|
import { GetCurrentTime } from '../utils/Common';
|
|
import FileUtils from '../utils/FileUtils';
|
|
|
|
let baseHost: string = AppStorage.get('host');
|
|
|
|
|
|
// 下载模型
|
|
export async function download() {
|
|
return request<object>({
|
|
host: baseHost as string,
|
|
url: '/para/initEsModel.ws',
|
|
method: http.RequestMethod.POST,
|
|
xml: false,
|
|
})
|
|
}
|
|
|
|
interface WR {
|
|
message?: string
|
|
code?: number
|
|
keystr?: string
|
|
}
|
|
|
|
// 通用监管接口
|
|
export async function writeObjectOut(params: RegulatoryInterfaceParams, filePath?: string): Promise<WR> {
|
|
const singlePlay: boolean = AppStorage.get('singlePlay')
|
|
if (singlePlay) {
|
|
return { code: 1 }
|
|
}
|
|
let JGHOST: string = AppStorage.get("JGHOST")
|
|
//获取监管接口地址路径
|
|
if (!JGHOST) {
|
|
const syssetParams: MASYSSETTableType[] = await GetSyncData<MASYSSETTableType>("MA_SYSSET");
|
|
|
|
syssetParams.forEach(sys => {
|
|
if (sys.v_no == '839') {
|
|
//是否是新监管
|
|
// globalThis.isJGNew = sys.v_value == '3'
|
|
AppStorage.setOrCreate('isJGNew', sys.v_value == '3')
|
|
}
|
|
if (sys.v_no == '900') {
|
|
// globalThis.JGHOST = validateIP(decodeURIComponent(sys.v_value))
|
|
AppStorage.setOrCreate('JGHOST', validateIP(decodeURIComponent(sys.v_value)))
|
|
}
|
|
})
|
|
}
|
|
// const { xtlb, jkxlh, jkid, drvexam } = params;
|
|
const isJGNew: boolean = AppStorage.get('isJGNew')
|
|
//新监管调用
|
|
if (isJGNew) {
|
|
return await writeObjectOutNew(params, filePath)
|
|
}
|
|
params.drvexam.zp = params.drvexam.zp === undefined ? undefined : encodeURIComponent(drvexam.zp)
|
|
|
|
const drvexamArrs = Reflect.ownKeys(params.drvexam)
|
|
.filter(dKey => params.drvexam[dKey] != undefined)
|
|
.map((key: string) => (
|
|
`<${key}>${params.drvexam[key]}</${key}>`));
|
|
|
|
if (filePath) {
|
|
const fileUtil = new FileUtils(globalThis.context);
|
|
await fileUtil.initFolder(filePath);
|
|
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify({
|
|
xtlb: params.xtlb,
|
|
jkxlh: params.jkxlh,
|
|
jkid: params.jkid,
|
|
drvexam: { ...params.drvexam, zp: '' },
|
|
}) + `\n`);
|
|
}
|
|
|
|
//对象转换成xml
|
|
JGHOST = AppStorage.get("JGHOST")
|
|
const temp = await request<object>({
|
|
host: JGHOST,
|
|
url: '/dems_ws/services/TmriOutAccess?wsdl',
|
|
data: `<?xml version="1.0"?>
|
|
<SOAP-ENV:Envelope
|
|
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
|
>
|
|
<SOAP-ENV:Body>
|
|
<writeObjectOut xmlns="http://service.es.doron">
|
|
<xtlb>${params.xtlb}</xtlb>
|
|
<jkxlh>${params.jkxlh}</jkxlh>
|
|
<jkid>${params.jkid}</jkid>
|
|
<UTF8XmlDoc>
|
|
<![CDATA[
|
|
<?xm lversion="1.0 "encoding="GBK"?>
|
|
<root>
|
|
<drvexam>
|
|
${drvexamArrs}
|
|
</drvexam>
|
|
</root>
|
|
]]>
|
|
</UTF8XmlDoc>
|
|
</writeObjectOut>
|
|
</SOAP-ENV:Body>
|
|
</SOAP-ENV:Envelope>`,
|
|
method: http.RequestMethod.POST,
|
|
xml: true
|
|
},)
|
|
if (filePath) {
|
|
const fileUtil = new FileUtils(globalThis.context);
|
|
await fileUtil.initFolder(filePath);
|
|
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`);
|
|
}
|
|
// const {code} = temp;
|
|
// if(code == '2300007' || code == '2300028'){
|
|
// return await writeObjectOut(params,filePath)
|
|
// }else{
|
|
// return temp
|
|
// }
|
|
return temp
|
|
}
|
|
|
|
interface UploadExamProgressDataParams {
|
|
carId: string
|
|
examinationRoomId: string
|
|
type: string
|
|
time: string
|
|
cardNo: string
|
|
examData: string
|
|
examStartTime: string
|
|
examEndTime: string
|
|
}
|
|
|
|
// 过程文件上传
|
|
export async function uploadExamProgressData(params: UploadExamProgressDataParams) {
|
|
// const singlePlay = globalThis.singlePlay
|
|
const singlePlay: boolean = AppStorage.get('singlePlay')
|
|
if (singlePlay) {
|
|
return
|
|
}
|
|
return request({
|
|
url: '/der2/services/exam/uploadExamDataFile.ws',
|
|
data: `<?xml version="1.0" encoding="UTF-8"?>
|
|
<uploadExamDataFileReq>
|
|
<head><time>${params.time}</time></head>
|
|
<body>
|
|
<carId>${params.carId}</carId>
|
|
<examinationRoomId>${params.examinationRoomId}</examinationRoomId>
|
|
<examData>${params.examData}</examData>
|
|
<type>${params.type}</type>
|
|
<cardNo>${params.cardNo}</cardNo>
|
|
<examStartTime>${params.examStartTime}</examStartTime>
|
|
<examEndTime>${params.examEndTime}</examEndTime>
|
|
</body>
|
|
</uploadExamDataFileReq>`,
|
|
method: http.RequestMethod.POST,
|
|
xml: true
|
|
})
|
|
}
|
|
|
|
interface UploadExamProgressDataParams2 {
|
|
carId: string
|
|
examinationRoomId: string
|
|
type: string
|
|
time: string
|
|
cardNo: string
|
|
examData: string
|
|
examStartTime: string
|
|
examEndTime: string
|
|
}
|
|
|
|
export async function uploadExamProgressData2(params: UploadExamProgressDataParams2) {
|
|
// const singlePlay = globalThis.singlePlay
|
|
const singlePlay: boolean = AppStorage.get('singlePlay')
|
|
if (singlePlay) {
|
|
return
|
|
}
|
|
return request<object>({
|
|
url: '/der2/services/exam/uploadExamDataFile.ws',
|
|
data: `<?xml version="1.0" encoding="UTF-8"?>
|
|
<uploadExamDataFileReq>
|
|
<head><time>${params.time}</time></head>
|
|
<body>
|
|
<carId>${params.carId}</carId>
|
|
<examinationRoomId>${params.examinationRoomId}</examinationRoomId>
|
|
<examData>${params.examData}</examData>
|
|
<type>${params.type}</type>
|
|
<cardNo>${params.cardNo}</cardNo>
|
|
<examStartTime>${params.examStartTime}</examStartTime>
|
|
<examEndTime>${params.examEndTime}</examEndTime>
|
|
</body>
|
|
</uploadExamDataFileReq>`,
|
|
method: http.RequestMethod.POST,
|
|
xml: true
|
|
})
|
|
}
|
|
|
|
interface UploadExamMileage {
|
|
carId: string
|
|
examinationRoomId: string
|
|
lsh: string
|
|
kslc: string
|
|
}
|
|
|
|
// 上传考试里程
|
|
export async function uploadExamMileage(params: UploadExamMileage) {
|
|
// const singlePlay = globalThis.singlePlay
|
|
const singlePlay: boolean = AppStorage.get('singlePlay')
|
|
|
|
if (singlePlay) {
|
|
return
|
|
}
|
|
const time = await GetCurrentTime()
|
|
return request<object>({
|
|
url: '/der2/services/exam/uploadExamMileage.ws',
|
|
data: `<?xml version="1.0" encoding="UTF-8"?>
|
|
<uploadExamMileageReq>
|
|
<head><time>${time}</time></head>
|
|
<body>
|
|
<carId>${params.carId}<carId>
|
|
<examinationRoomId>${params.examinationRoomId}<examinationRoomId>
|
|
<lsh>${params.lsh}<lsh>
|
|
<kskssj>${params.examinationRoomId}<kskssj>
|
|
<kslc>${params.kslc}<kslc>
|
|
</body>
|
|
</uploadExamMileageReq>`,
|
|
method: http.RequestMethod.POST,
|
|
xml: true
|
|
})
|
|
}
|
|
|
|
// 上传考试成绩
|
|
export async function uploadExamGrade(params: ESObject) {
|
|
// const singlePlay = globalThis.singlePlay
|
|
const singlePlay: boolean = AppStorage.get('singlePlay')
|
|
if (singlePlay) {
|
|
return
|
|
}
|
|
const paramsArrs = Reflect.ownKeys(params).map((key: string) => (`<${key}>${params[key]}</${key}>`))
|
|
const time = await getCurrentTime()
|
|
return request<object>({
|
|
url: '/der2/services/exam/uploadExamGrade.ws',
|
|
data: `<?xml version="1.0" encoding="UTF-8"?>
|
|
<uploadExamGradeReq>
|
|
<head><time>${time}</time></head>
|
|
<body>
|
|
${paramsArrs}
|
|
</body>
|
|
</uploadExamGradeReq>`,
|
|
method: http.RequestMethod.POST,
|
|
xml: true
|
|
})
|
|
}
|
|
|
|
function validateIP(path: string) {
|
|
const reg = new RegExp(`(\w+):\/\/([^/:]+)(:\d*)?`)
|
|
const result = path.match(reg);
|
|
return result[0]
|
|
}
|
|
|
|
// 上传运行时常
|
|
export async function uploadHarmonyLiCheng(data: object) {
|
|
return request<object>({
|
|
url: '/der2/services/data/harmonyLiCheng.ws',
|
|
data,
|
|
method: http.RequestMethod.POST,
|
|
xml: false
|
|
})
|
|
}
|