2024-07-31 13:47:40 +08:00
|
|
|
import { getSyncData } from '../common/service/initable';
|
2025-02-21 15:38:00 +08:00
|
|
|
import request from '../common/utils/request';
|
2024-08-05 09:47:44 +08:00
|
|
|
import FileUtil from '../common/utils/File';
|
2025-02-28 10:46:28 +08:00
|
|
|
import { HandleCenterCode, NewTcpClient, XmlToJson } from '../common/utils/new/tcp';
|
|
|
|
|
import { PrintStr } from '../common/utils/tools';
|
2025-02-21 15:38:00 +08:00
|
|
|
|
|
|
|
|
let baseHost = globalThis.host;
|
2024-07-31 13:47:40 +08:00
|
|
|
|
|
|
|
|
//监管接口序列号映射
|
|
|
|
|
const gjxlhObj = {
|
|
|
|
|
'17C51': '02-21-000009',
|
|
|
|
|
'17C52': '02-21-000010',
|
|
|
|
|
'17C53': '02-21-000011',
|
|
|
|
|
'17C54': '02-21-000012',
|
|
|
|
|
'17C55': '02-21-000013',
|
|
|
|
|
'17C56': '02-21-000014',
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-21 15:38:00 +08:00
|
|
|
interface WR {
|
|
|
|
|
message?: string
|
|
|
|
|
code: number
|
2024-08-12 10:19:31 +08:00
|
|
|
}
|
2024-12-31 17:51:25 +08:00
|
|
|
|
2025-02-21 15:38:00 +08:00
|
|
|
export default async function writeObjectOutNew(data, filePath): Promise<WR> {
|
2024-08-05 09:47:44 +08:00
|
|
|
const fileUtil = new FileUtil(globalThis.context);
|
2024-07-31 13:47:40 +08:00
|
|
|
const {jkid , drvexam} = data;
|
|
|
|
|
const basic = await getBasicConfig(jkid);
|
|
|
|
|
const params = await getParams(jkid, drvexam);
|
|
|
|
|
const {wglb,jkxlh,glbm,jgbh,sjbs} = basic;
|
|
|
|
|
|
2025-02-21 15:38:00 +08:00
|
|
|
if (filePath) {
|
|
|
|
|
await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify({
|
|
|
|
|
wglb,
|
|
|
|
|
jkxlh,
|
|
|
|
|
glbm,
|
|
|
|
|
jgbh,
|
|
|
|
|
sjbs,
|
|
|
|
|
data: params.data,
|
|
|
|
|
file: {
|
|
|
|
|
...params.file, param: []
|
|
|
|
|
},
|
2024-12-31 17:51:25 +08:00
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// let connectTimeout = sjbs === '02-21-000014' ?60000:1
|
2025-02-21 15:38:00 +08:00
|
|
|
console.info('surenjun', '调用新监管')
|
2025-01-14 19:43:14 +08:00
|
|
|
let temp
|
|
|
|
|
try {
|
2025-02-28 10:46:28 +08:00
|
|
|
// if (jkid === "17C51") {
|
|
|
|
|
// temp = await request({
|
|
|
|
|
// host: globalThis.JGHOST,
|
|
|
|
|
// method: 'post',
|
|
|
|
|
// //是否是新中心
|
|
|
|
|
// isNewCenter: true,
|
|
|
|
|
// xml: true,
|
|
|
|
|
// 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">
|
|
|
|
|
// <wglb>${wglb}</wglb>
|
|
|
|
|
// <jkxlh>${jkxlh}</jkxlh>
|
|
|
|
|
// <glbm>${glbm}</glbm>
|
|
|
|
|
// <jgbh>${jgbh}</jgbh>
|
|
|
|
|
// <sjbs>${sjbs}</sjbs>
|
|
|
|
|
// <data>${JSON.stringify(params.data)}</data>
|
|
|
|
|
// <file>${JSON.stringify(params.file)}</file>
|
|
|
|
|
// </writeObjectOut>
|
|
|
|
|
// </SOAP-ENV:Body>
|
|
|
|
|
// </SOAP-ENV:Envelope>`,
|
|
|
|
|
// })
|
|
|
|
|
// } else {
|
|
|
|
|
temp = await getMessageByEnd(params, basic)
|
|
|
|
|
console.log("zj result", JSON.stringify(temp))
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("zj 新监管错误")
|
|
|
|
|
temp = e
|
|
|
|
|
}
|
|
|
|
|
console.log("zj temp message: ", JSON.stringify(temp))
|
|
|
|
|
if (filePath) {
|
|
|
|
|
await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`);
|
|
|
|
|
}
|
|
|
|
|
return temp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getMessageByEnd(params, basic) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const timeoutId = setTimeout(() => {
|
|
|
|
|
PrintStr(params, 100)
|
|
|
|
|
// 如果超时,抛出错误
|
|
|
|
|
console.log("zj tcp timeout")
|
|
|
|
|
reject(new Error("Timeout: No data received within 15 seconds"));
|
|
|
|
|
}, 15000);
|
|
|
|
|
const {wglb,jkxlh,glbm,jgbh,sjbs} = basic;
|
|
|
|
|
let baseUrl = globalThis.JGHOST ? globalThis.JGHOST : globalThis.host
|
|
|
|
|
let key = new Date().getTime()
|
|
|
|
|
// 走后置机
|
|
|
|
|
params.file.param = [{
|
|
|
|
|
field: '', data: ""
|
|
|
|
|
}]
|
|
|
|
|
let data = {
|
|
|
|
|
url: `${baseUrl}/dems_ws/services/TmriOutAccess?wsdl`,
|
|
|
|
|
serialNumber: key,
|
|
|
|
|
type: 1,
|
|
|
|
|
method: "post",
|
|
|
|
|
isNewCenter: true,
|
|
|
|
|
data: `<?xml version="1.0"?>
|
2025-02-25 16:03:54 +08:00
|
|
|
<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">
|
|
|
|
|
<wglb>${wglb}</wglb>
|
|
|
|
|
<jkxlh>${jkxlh}</jkxlh>
|
|
|
|
|
<glbm>${glbm}</glbm>
|
|
|
|
|
<jgbh>${jgbh}</jgbh>
|
|
|
|
|
<sjbs>${sjbs}</sjbs>
|
|
|
|
|
<data>${JSON.stringify(params.data)}</data>
|
|
|
|
|
<file>${JSON.stringify(params.file)}</file>
|
|
|
|
|
</writeObjectOut>
|
|
|
|
|
</SOAP-ENV:Body>
|
|
|
|
|
</SOAP-ENV:Envelope>`,
|
2025-02-28 10:46:28 +08:00
|
|
|
contentType: 'text/xml',
|
|
|
|
|
isHeartBeat: "0",
|
|
|
|
|
}
|
|
|
|
|
console.log("zj guocheng", JSON.stringify(data))
|
|
|
|
|
NewTcpClient.sendMsg(`^#${JSON.stringify(data)}#$`)
|
|
|
|
|
let cache = ""
|
|
|
|
|
NewTcpClient.onMessage(async (value) => {
|
|
|
|
|
console.log("zj onMessage", value)
|
|
|
|
|
// 先找到^#和#$开始结束符号
|
|
|
|
|
cache += value
|
|
|
|
|
let start = cache.indexOf("^#")
|
|
|
|
|
let end = cache.indexOf("#$")
|
|
|
|
|
if (start !== -1 && end !== -1) {
|
|
|
|
|
let message = cache.slice(start + 2, end)
|
|
|
|
|
cache = cache.slice(end + 2)
|
|
|
|
|
let tempIndex = message.indexOf("^#")
|
|
|
|
|
while (tempIndex > -1) {
|
|
|
|
|
message = message.slice(tempIndex + 2)
|
|
|
|
|
tempIndex = message.indexOf("^#")
|
|
|
|
|
}
|
|
|
|
|
let result: any = JSON.parse(message)
|
|
|
|
|
if (Number(result.serialNumber) === Number(key) && !result.url) {
|
|
|
|
|
let temp: any = XmlToJson(result.data)
|
|
|
|
|
if (temp.Envelope) {
|
|
|
|
|
console.log("zj accept", JSON.stringify(temp))
|
|
|
|
|
const msgXml = temp.Envelope.Body.writeObjectOutResponse.return;
|
|
|
|
|
const dd = HandleCenterCode(msgXml, true);
|
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
|
resolve(dd)
|
2025-02-25 16:03:54 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-02-28 10:46:28 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
2024-07-31 13:47:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getParams(jkid, drvexam) {
|
|
|
|
|
const examSubject = globalThis.carInfo.examSubject;
|
|
|
|
|
switch (jkid) {
|
|
|
|
|
//开始考试
|
|
|
|
|
case '17C51':
|
|
|
|
|
return {
|
|
|
|
|
data: {
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
|
|
|
|
param: {
|
|
|
|
|
sfzmhm: drvexam.sfzmhm,
|
|
|
|
|
kchp: decodeURI(drvexam.kchp),
|
|
|
|
|
kskm: examSubject,
|
|
|
|
|
ksxl: examSubject == 3 ? drvexam.ksxl : undefined,
|
|
|
|
|
kssj: drvexam.kssj
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
file: {
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
2024-12-30 12:56:27 +08:00
|
|
|
// param: [{ field: '', data: examSubject == 2 ? encodeURIComponent(drvexam.zp) : drvexam.zp }]
|
|
|
|
|
param: [{ field: '', data: drvexam.zp }]
|
2024-07-31 13:47:40 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//项目开始
|
|
|
|
|
case '17C52':
|
|
|
|
|
return {
|
|
|
|
|
data: {
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
|
|
|
|
param: {
|
|
|
|
|
sfzmhm: drvexam.sfzmhm,
|
|
|
|
|
kskm: drvexam.kskm,
|
|
|
|
|
ksxm: drvexam.ksxm,
|
|
|
|
|
ksxl: examSubject == 3 ? drvexam.ksxl : undefined,
|
|
|
|
|
kchp: decodeURI(drvexam.kchp),
|
|
|
|
|
//TODO 待验证 科目三无
|
|
|
|
|
sbbh: examSubject == 3 ? undefined : drvexam.sbxh,
|
|
|
|
|
kssj: drvexam.kssj
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
file: {
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
|
|
|
|
param: [{ field: '', data: '' }]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//扣分
|
|
|
|
|
case '17C53':
|
|
|
|
|
return {
|
|
|
|
|
data: {
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
|
|
|
|
param: {
|
|
|
|
|
kffs: drvexam.kffs,
|
|
|
|
|
kfsj: drvexam.kfsj,
|
|
|
|
|
kfxm: drvexam.kfxm,
|
|
|
|
|
kfxmmx: drvexam.kfxmmx,
|
|
|
|
|
kskm: examSubject,
|
|
|
|
|
ksxm: drvexam.ksxm,
|
|
|
|
|
sfzmhm: drvexam.sfzmhm
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
file: {
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
|
|
|
|
param: [{ field: '', data: '' }]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//过程照片
|
|
|
|
|
case '17C54':
|
|
|
|
|
return {
|
|
|
|
|
data: {
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
|
|
|
|
param: {
|
|
|
|
|
cs: drvexam.cs,
|
|
|
|
|
kskm: drvexam.kskm,
|
|
|
|
|
ksxm: drvexam.ksxm,
|
|
|
|
|
sfzmhm: drvexam.sfzmhm,
|
|
|
|
|
zpsj: drvexam.zpsj
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
file: {
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
2024-12-30 12:56:27 +08:00
|
|
|
param: [{ field: '', data: drvexam.zp }]
|
2024-07-31 13:47:40 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//项目结束
|
|
|
|
|
case '17C55':
|
|
|
|
|
return {
|
|
|
|
|
data: {
|
|
|
|
|
param: {
|
|
|
|
|
czlx: drvexam.czlx,
|
|
|
|
|
jssj: drvexam.jssj,
|
|
|
|
|
kskm: examSubject,
|
|
|
|
|
ksxl: drvexam.ksxl,
|
2024-12-30 12:56:27 +08:00
|
|
|
sbbh: examSubject == 3 ? undefined : drvexam.sbxh,
|
2024-07-31 13:47:40 +08:00
|
|
|
ksxm: drvexam.ksxm,
|
|
|
|
|
sfzmhm: drvexam.sfzmhm
|
|
|
|
|
},
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
|
|
|
|
},
|
|
|
|
|
file: { sjbs: gjxlhObj[jkid], param: [{ field: '', data: '' }] }
|
|
|
|
|
}
|
|
|
|
|
//考试结束
|
|
|
|
|
case '17C56':
|
|
|
|
|
return {
|
|
|
|
|
data: {
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
|
|
|
|
param: {
|
|
|
|
|
dwlc: drvexam.dwlc,
|
|
|
|
|
ghks: "0",
|
|
|
|
|
jssj: drvexam.jssj,
|
|
|
|
|
kscj: drvexam.kscj,
|
|
|
|
|
kskm: examSubject,
|
|
|
|
|
kslc: drvexam.kslc,
|
|
|
|
|
sfzmhm: drvexam.sfzmhm
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
file: { sjbs: gjxlhObj[jkid], param: [{ field: '', data: drvexam.zp }] }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取基础信息
|
|
|
|
|
async function getBasicConfig(jkid) {
|
|
|
|
|
const examSubject = globalThis.carInfo.examSubject;
|
|
|
|
|
const syssetParam = await getSyncData('MA_SYSSET');
|
|
|
|
|
let syssetObj = {};
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
syssetParam.forEach(sys => {
|
|
|
|
|
syssetObj[sys.v_no] = decodeURIComponent(sys.v_value)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
//外挂类别
|
|
|
|
|
wglb: examSubject == 2 ? "700203" : "700204",
|
|
|
|
|
//监管接口序列号
|
|
|
|
|
jkxlh: syssetObj['901'],
|
|
|
|
|
//管理部门
|
|
|
|
|
glbm: syssetObj['903'],
|
|
|
|
|
//考场序号
|
|
|
|
|
jgbh: syssetObj['905'],
|
|
|
|
|
//接口id
|
|
|
|
|
sjbs: gjxlhObj[jkid],
|
|
|
|
|
}
|
|
|
|
|
}
|