feat:修改
This commit is contained in:
parent
ec42803348
commit
47a575a464
@ -8,7 +8,7 @@ let baseHost = globalThis.host;
|
||||
|
||||
// 下载模型
|
||||
export async function download() {
|
||||
return request({
|
||||
return await request({
|
||||
host: baseHost,
|
||||
url: '/para/initEsModel.ws',
|
||||
method: 'post',
|
||||
@ -21,8 +21,9 @@ interface WR{
|
||||
code?:number
|
||||
keystr?:string
|
||||
}
|
||||
|
||||
// 通用监管接口
|
||||
export async function writeObjectOut(params,filePath?:string): Promise<WR> {
|
||||
export async function writeObjectOut(params, filePath?:string): Promise<WR> {
|
||||
const singlePlay = globalThis.singlePlay
|
||||
if (singlePlay) {
|
||||
return {code:1}
|
||||
@ -55,8 +56,8 @@ export async function writeObjectOut(params,filePath?:string): Promise<WR> {
|
||||
`<${key}>${drvexam[key]}</${key}>`));
|
||||
|
||||
console.log('surenjun filePath=>',filePath);
|
||||
if(filePath){
|
||||
const fileUtil = new FileUtil(globalThis.context);
|
||||
if(filePath){
|
||||
await fileUtil.initFolder(filePath);
|
||||
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify({
|
||||
xtlb,jkxlh,jkid,drvexam:{...drvexam,zp:''},
|
||||
@ -64,7 +65,9 @@ export async function writeObjectOut(params,filePath?:string): Promise<WR> {
|
||||
}
|
||||
|
||||
//对象转换成xml
|
||||
const temp = request({
|
||||
let temp = {}
|
||||
try {
|
||||
temp = await request({
|
||||
host: globalThis.JGHOST,
|
||||
url: '/dems_ws/services/TmriOutAccess?wsdl',
|
||||
data: `<?xml version="1.0"?>
|
||||
@ -94,17 +97,12 @@ export async function writeObjectOut(params,filePath?:string): Promise<WR> {
|
||||
method: 'post',
|
||||
xml: true
|
||||
},)
|
||||
} catch (e) {
|
||||
temp =e
|
||||
}
|
||||
if(filePath){
|
||||
const fileUtil = new FileUtil(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
|
||||
}
|
||||
|
||||
@ -115,7 +113,7 @@ export async function uploadExamProgressData(params) {
|
||||
if (singlePlay) {
|
||||
return
|
||||
}
|
||||
return request({
|
||||
return await request({
|
||||
url: '/der2/services/exam/uploadExamDataFile.ws',
|
||||
data: `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<uploadExamDataFileReq>
|
||||
@ -142,7 +140,7 @@ export async function uploadExamMileage(params) {
|
||||
return
|
||||
}
|
||||
const time = await getCurrentTime()
|
||||
return request({
|
||||
return await request({
|
||||
url: '/der2/services/exam/uploadExamMileage.ws',
|
||||
data: `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<uploadExamMileageReq>
|
||||
@ -168,7 +166,7 @@ export async function uploadExamGrade(params) {
|
||||
}
|
||||
const paramsArrs = Reflect.ownKeys(params).map((key: string) => (`<${key}>${params[key]}</${key}>`))
|
||||
const time = await getCurrentTime()
|
||||
return request({
|
||||
return await request({
|
||||
url: '/der2/services/exam/uploadExamGrade.ws',
|
||||
data: `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<uploadExamGradeReq>
|
||||
@ -190,9 +188,10 @@ function validateIP(path: string) {
|
||||
|
||||
// 上传运行时常
|
||||
export async function uploadHarmonyLiCheng(data) {
|
||||
return request({
|
||||
return await request({
|
||||
url: '/der2/services/data/harmonyLiCheng.ws',
|
||||
data,
|
||||
method: 'post',
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -35,10 +35,10 @@ export default async function writeObjectOutNew(data,filePath): Promise<WR> {
|
||||
}
|
||||
|
||||
// let connectTimeout = sjbs === '02-21-000014' ?60000:1
|
||||
|
||||
console.info('surenjun','调用新监管')
|
||||
|
||||
const temp = await request({
|
||||
let temp
|
||||
try {
|
||||
temp = await request({
|
||||
host: globalThis.JGHOST,
|
||||
method: 'post',
|
||||
//是否是新中心
|
||||
@ -64,17 +64,12 @@ export default async function writeObjectOutNew(data,filePath): Promise<WR> {
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>`,
|
||||
})
|
||||
} catch (e) {
|
||||
temp = e
|
||||
}
|
||||
if(filePath){
|
||||
const fileUtil = new FileUtil(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 writeObjectOutNew(params,filePath)
|
||||
// }else{
|
||||
// return temp
|
||||
// }
|
||||
return temp
|
||||
|
||||
}
|
||||
|
||||
@ -1,13 +1,10 @@
|
||||
import http from '@ohos.net.http';
|
||||
import convertxml from '@ohos.convertxml';
|
||||
import prompt from '@ohos.prompt'
|
||||
import { sendGreen } from '../../pages/judgeSDK/utils/judgeCommon';
|
||||
import {GlobalConfig} from '../../config/index'
|
||||
import FileUtil from '../../common/utils/File';
|
||||
import { dateFormat } from '../utils/tools'
|
||||
import { GlobalConfig } from '../../config/index'
|
||||
|
||||
const config = {
|
||||
host:GlobalConfig.host,
|
||||
host: GlobalConfig.host,
|
||||
}
|
||||
|
||||
/**
|
||||
@ -22,27 +19,90 @@ const config = {
|
||||
*/
|
||||
// let httpRequest = http.createHttp();
|
||||
|
||||
export default async function request(req: any) {
|
||||
const {url,params = {},data = {},xml,method = 'get',host,isNewCenter = false} = req;
|
||||
export default async function request(req: any): Promise<any> {
|
||||
return new Promise((reslove, reject) => {
|
||||
let httpRequest = http.createHttp();
|
||||
const {url,params = {},data = {},xml,method = 'get',host,isNewCenter = false} = req;
|
||||
try {
|
||||
const options = {
|
||||
method: http.RequestMethod[method.toUpperCase()],
|
||||
header: {
|
||||
'Content-Type': xml ? 'text/xml' : 'application/json'
|
||||
},
|
||||
extraData: xml ? data : JSON.stringify(data),
|
||||
//15秒超时
|
||||
connectTimeout:15 * 1000
|
||||
}
|
||||
//params转url拼接参数
|
||||
let paramsStr = Reflect.ownKeys(params).reduce((p: string, n: string) => (`${p}${n}=${params[n]}&`), '?') || '';
|
||||
paramsStr = paramsStr.toString();
|
||||
paramsStr = paramsStr.substring(0, paramsStr.length-1)
|
||||
try {
|
||||
let baseUrl=host?host:globalThis.host
|
||||
paramsStr = paramsStr.substring(0, paramsStr.length - 1)
|
||||
let baseUrl = host ? host : globalThis.host
|
||||
// let baseUrl=host?config.csptHost:config.host'
|
||||
console.log('响应头地址1' + baseUrl,url,options.extraData.length)
|
||||
const {result,responseCode} = await httpRequest.request(`${baseUrl}${url}${paramsStr}`, {...options});
|
||||
console.log('响应头地址1' + baseUrl, url, options.extraData.length)
|
||||
// const {result,responseCode} = await
|
||||
httpRequest.request(`${baseUrl}${url}${paramsStr}`, {
|
||||
...options
|
||||
})
|
||||
.then(async(data) => {
|
||||
const result = data.result
|
||||
console.log('响应头地址' + JSON.stringify(result))
|
||||
let res: any = xml ? xmlToJson(result, url) : result;
|
||||
console.log('响应头地址' + JSON.stringify(res))
|
||||
|
||||
let resObj = null;
|
||||
if (typeof res === "string") {
|
||||
res = JSON.parse(res)
|
||||
}
|
||||
//处理中心服务code
|
||||
if (res.Envelope) {
|
||||
const msgXml = res.Envelope.Body.writeObjectOutResponse.return;
|
||||
//Envelope.Body.writeObjectOutResponse.return
|
||||
const dd = handleCenterCode(msgXml, isNewCenter);
|
||||
httpRequest.destroy();
|
||||
// @ts-ignore
|
||||
reslove(dd)
|
||||
return
|
||||
}
|
||||
|
||||
if (!xml) {
|
||||
if (res.head.resultCode === '0') {
|
||||
// return res
|
||||
httpRequest.destroy();
|
||||
reslove(res)
|
||||
return
|
||||
} else {
|
||||
const resultMessage = res?.body?.resultMessage || res?.head?.resultMessage
|
||||
prompt.showToast({
|
||||
message: decodeURIComponent(resultMessage),
|
||||
duration: 3000
|
||||
});
|
||||
httpRequest.destroy();
|
||||
reject(false)
|
||||
}
|
||||
}
|
||||
for (let i in res) {
|
||||
resObj = res[i].head
|
||||
}
|
||||
console.info('jiangsong:res in request' + url + JSON.stringify(resObj))
|
||||
if (resObj.resultCode === '0') {
|
||||
httpRequest.destroy();
|
||||
reslove(res)
|
||||
return
|
||||
} else {
|
||||
prompt.showToast({
|
||||
message: decodeURIComponent(resObj.resultMessage),
|
||||
duration: 3000
|
||||
});
|
||||
httpRequest.destroy();
|
||||
reject(res)
|
||||
}
|
||||
}).catch(Error=>{
|
||||
console.info('test-error0' + url + ' error:resp: ' + JSON.stringify(Error.message))
|
||||
prompt.showToast({
|
||||
message: Error?.message,
|
||||
duration: 5000
|
||||
});
|
||||
reject(Error)
|
||||
})
|
||||
// fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(arrList))
|
||||
// writeLog({
|
||||
// time:dateFormat(new Date()),
|
||||
@ -51,89 +111,54 @@ export default async function request(req: any) {
|
||||
// extraData: JSON.stringify(data),
|
||||
// state:'end'
|
||||
// })
|
||||
console.log('响应头地址' + JSON.stringify(result))
|
||||
let res:any = xml ? xmlToJson(result,url) : result;
|
||||
console.log('响应头地址' + JSON.stringify(res))
|
||||
|
||||
let resObj = null;
|
||||
if(typeof res === "string"){
|
||||
res=JSON.parse(res)
|
||||
}
|
||||
//处理中心服务code
|
||||
if(res.Envelope){
|
||||
const msgXml = res.Envelope.Body.writeObjectOutResponse.return;
|
||||
//Envelope.Body.writeObjectOutResponse.return
|
||||
const dd = handleCenterCode(msgXml,isNewCenter);
|
||||
httpRequest.destroy();
|
||||
return dd
|
||||
}
|
||||
|
||||
if(!xml){
|
||||
if(res.head.resultCode === '0'){
|
||||
return res
|
||||
}else{
|
||||
const resultMessage = res?.body?.resultMessage || res?.head?.resultMessage
|
||||
prompt.showToast({
|
||||
message: decodeURIComponent(resultMessage),
|
||||
duration: 3000
|
||||
});
|
||||
return false
|
||||
}
|
||||
}
|
||||
for( let i in res ) {
|
||||
resObj = res[i].head
|
||||
}
|
||||
console.info('jiangsong:res in request' + url + JSON.stringify(resObj))
|
||||
if(resObj.resultCode === '0') {
|
||||
httpRequest.destroy();
|
||||
return res
|
||||
}else {
|
||||
prompt.showToast({
|
||||
message: decodeURIComponent(resObj.resultMessage),
|
||||
duration: 3000
|
||||
});
|
||||
httpRequest.destroy();
|
||||
return res
|
||||
}
|
||||
} catch (e) {
|
||||
console.info('test-error' + url + ' error:resp: '+ JSON.stringify(e))
|
||||
if(!e||!(e?.message)){
|
||||
console.info('test-error' + url + ' error:resp: ' + JSON.stringify(e))
|
||||
if (!e || !(e?.message)) {
|
||||
httpRequest.destroy();
|
||||
return {code:-1}
|
||||
reject({
|
||||
code: -1
|
||||
})
|
||||
// httpRequest.destroy();
|
||||
// return {code:-1}
|
||||
}
|
||||
const code = e?.code;
|
||||
prompt.showToast({
|
||||
message: e?.message,
|
||||
duration: 5000
|
||||
});
|
||||
httpRequest.destroy();
|
||||
switch (code){
|
||||
//断网
|
||||
case 2300007: return {code:2300007}
|
||||
// 超时
|
||||
case 2300028: return {code:2300028}
|
||||
default:
|
||||
}
|
||||
return {code:e.code}
|
||||
reject({
|
||||
code: e.code
|
||||
})
|
||||
// return {code:e.code}
|
||||
// return {code:e.code}
|
||||
// httpRequest.destroy();
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
async function writeLog(param){
|
||||
const fileUtil = new FileUtil(globalThis.context)
|
||||
const folderPath = await fileUtil.initFolder(`/errorMsg/`);
|
||||
fileUtil.editFile(`${folderPath}/request.txt`, JSON.stringify(param)+`\n`)
|
||||
|
||||
}
|
||||
|
||||
|
||||
//xml格式转JSON
|
||||
function xmlToJson(result,url) {
|
||||
console.log("xmlToJson begin",url);
|
||||
let xmlOptions = {trim : false, declarationKey:"_declaration",
|
||||
instructionKey : "_instruction", attributesKey : "_attributes",
|
||||
textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype",
|
||||
commentKey : "_comment", parentKey : "_parent", typeKey : "_type",
|
||||
nameKey : "_name", elementsKey : "_elements", "skipPreprocess" : true}
|
||||
function xmlToJson(result, url) {
|
||||
console.log("xmlToJson begin", url);
|
||||
let xmlOptions = {
|
||||
trim: false,
|
||||
declarationKey: "_declaration",
|
||||
instructionKey: "_instruction",
|
||||
attributesKey: "_attributes",
|
||||
textKey: "_text",
|
||||
cdataKey: "_cdata",
|
||||
doctypeKey: "_doctype",
|
||||
commentKey: "_comment",
|
||||
parentKey: "_parent",
|
||||
typeKey: "_type",
|
||||
nameKey: "_name",
|
||||
elementsKey: "_elements",
|
||||
"skipPreprocess": true
|
||||
}
|
||||
|
||||
let strXml = result.toString();
|
||||
let conv = new convertxml.ConvertXML();
|
||||
@ -144,41 +169,41 @@ function xmlToJson(result,url) {
|
||||
let {_elements:xmlArr} = conv.convertToJSObject(strXml, xmlOptions);
|
||||
console.log("xmlToJson deeml begin");
|
||||
let res = deeml(xmlArr);
|
||||
console.log("xmlToJson end",url);
|
||||
console.log("xmlToJson end", url);
|
||||
return res
|
||||
}
|
||||
|
||||
//处理中心服务code
|
||||
function handleCenterCode(msgXml,isNewCenter){
|
||||
function handleCenterCode(msgXml, isNewCenter) {
|
||||
//新监管
|
||||
if(isNewCenter){
|
||||
if (isNewCenter) {
|
||||
const msg = JSON.parse(msgXml);
|
||||
const result = msg?.data[0]?.result;
|
||||
if(result){
|
||||
if (result) {
|
||||
const {code,message,retval} = result
|
||||
if(code != '1'){
|
||||
if (code != '1') {
|
||||
const rMessage = decodeURIComponent(message as string)
|
||||
// globalThis.title=rMessage
|
||||
// globalThis.type='1'
|
||||
// globalThis.errorDialog.open()
|
||||
prompt.showToast({
|
||||
message:rMessage,
|
||||
message: rMessage,
|
||||
duration: 3000
|
||||
});
|
||||
return {code,message}
|
||||
}else{
|
||||
return { code ,keystr:retval}
|
||||
return { code, message }
|
||||
} else {
|
||||
return { code, keystr: retval }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//正则匹配code message字段
|
||||
const [code,message,keystr] = [/<code>(.*)<\/code>/i,/<message>(.*)<\/message>/i,/<keystr>(.*)<\/keystr>/i].map(pattern=>{
|
||||
const [code, message, keystr] = [/<code>(.*)<\/code>/i, /<message>(.*)<\/message>/i, /<keystr>(.*)<\/keystr>/i].map(pattern => {
|
||||
const patternArr = pattern.exec(msgXml);
|
||||
return patternArr && patternArr[1]
|
||||
});
|
||||
|
||||
if(code != '1'){
|
||||
if (code != '1') {
|
||||
prompt.showToast({
|
||||
message: decodeURIComponent(message as string),
|
||||
duration: 3000
|
||||
@ -186,56 +211,58 @@ function handleCenterCode(msgXml,isNewCenter){
|
||||
// globalThis.type='1'
|
||||
// globalThis.title=decodeURIComponent(message as string)
|
||||
// globalThis.errorDialog.open()
|
||||
return {code,message:decodeURIComponent(message)}
|
||||
}else{
|
||||
return { code ,keystr, message }
|
||||
return { code, message: decodeURIComponent(message) }
|
||||
} else {
|
||||
return { code, keystr, message }
|
||||
}
|
||||
}
|
||||
|
||||
//JSON转xml格式
|
||||
const deeml = (elements,_name?)=>{
|
||||
const deeml = (elements, _name?) => {
|
||||
const json = {}
|
||||
|
||||
elements.map(ele =>{
|
||||
elements.map(ele => {
|
||||
const _elements = ele._elements
|
||||
if(ele._type === 'element'){
|
||||
if(_elements==undefined){
|
||||
if (ele._type === 'element') {
|
||||
if (_elements == undefined) {
|
||||
return
|
||||
}
|
||||
const thisJson = json[ele._name]
|
||||
if(_elements && _elements.length === 1 && _elements[0]._type === 'text'){
|
||||
if (_elements && _elements.length === 1 && _elements[0]._type === 'text') {
|
||||
// 如果值存在了
|
||||
if(thisJson){
|
||||
if (thisJson) {
|
||||
handleCommonArr(_elements[0]._text)
|
||||
}else{
|
||||
} else {
|
||||
json[ele._name] = _elements[0]._text
|
||||
}
|
||||
}else{
|
||||
if(thisJson){
|
||||
handleCommonArr( deeml(ele._elements,ele._name) )
|
||||
}else{
|
||||
json[ele._name] = deeml(ele._elements,ele._name)
|
||||
} else {
|
||||
if (thisJson) {
|
||||
handleCommonArr(deeml(ele._elements, ele._name))
|
||||
} else {
|
||||
json[ele._name] = deeml(ele._elements, ele._name)
|
||||
}
|
||||
}
|
||||
|
||||
//通用处理重复标签
|
||||
function handleCommonArr(obj){
|
||||
if(thisJson){
|
||||
if(Array.isArray(thisJson)){
|
||||
function handleCommonArr(obj) {
|
||||
if (thisJson) {
|
||||
if (Array.isArray(thisJson)) {
|
||||
json[ele._name].push(obj)
|
||||
}else{
|
||||
json[ele._name] = [json[ele._name],obj]
|
||||
} else {
|
||||
json[ele._name] = [json[ele._name], obj]
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
json[ele._name] = obj
|
||||
}
|
||||
}0
|
||||
}else{
|
||||
}
|
||||
|
||||
0
|
||||
} else {
|
||||
//标签上有属性
|
||||
if(ele._attributes){
|
||||
if (ele._attributes) {
|
||||
json[_name] = {
|
||||
value: ele._text,
|
||||
attributes:ele.__attributes
|
||||
attributes: ele.__attributes
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -245,5 +272,5 @@ const deeml = (elements,_name?)=>{
|
||||
};
|
||||
|
||||
function isEmpty(param) {
|
||||
return!Object.keys(param).length;
|
||||
return !Object.keys(param).length;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user