280 lines
		
	
	
		
			9.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			280 lines
		
	
	
		
			9.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| import request from '../utils/Request';
 | |
| import writeObjectOutNew from './judgeNew';
 | |
| import http from '@ohos.net.http';
 | |
| import { MASYSSETTableType, RegulatoryInterfaceParams, WuxiExamType } from '../model';
 | |
| import { GetSyncData } from '../utils/table/Operation';
 | |
| import { GetCurrentTime } from '../utils/Common';
 | |
| import FileUtils from '../utils/FileUtils';
 | |
| import common from '@ohos.app.ability.common';
 | |
| import { dConsole } from '../utils/LogWorker';
 | |
| import { JudgeTag } from '../config';
 | |
| 
 | |
| let baseHost: string = AppStorage.get<string>('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,
 | |
|                                      context: common.UIAbilityContext): Promise<WR> {
 | |
| 
 | |
|   const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
 | |
|   if (singlePlay) {
 | |
|     return { code: 1 }
 | |
|   }
 | |
|   let JGHOST: string = AppStorage.get<string>("JGHOST") || ""
 | |
|   let isJGNew: boolean = false
 | |
|   //获取监管接口地址路径
 | |
|   if (!JGHOST) {
 | |
|     const syssetParams: MASYSSETTableType[] = await GetSyncData<MASYSSETTableType>("MA_SYSSET");
 | |
|     syssetParams.forEach(sys => {
 | |
|       if (sys.v_no == '839') {
 | |
|         //是否是新监管
 | |
|         isJGNew = sys.v_value == '3'
 | |
|         AppStorage.setOrCreate('isJGNew', isJGNew)
 | |
|       }
 | |
|       if (sys.v_no == '900') {
 | |
|         const ip = decodeURIComponent(sys.v_value || "")
 | |
|         JGHOST = validateIP(ip) || ""
 | |
|         dConsole.log(JudgeTag, "监管地址取值", JGHOST)
 | |
|         AppStorage.setOrCreate('JGHOST', JGHOST)
 | |
|       }
 | |
|     })
 | |
|   }
 | |
|   //新监管调用
 | |
|   if (isJGNew) {
 | |
|     dConsole.log(JudgeTag, "新监管")
 | |
|     return await writeObjectOutNew(params, filePath, context)
 | |
|   }
 | |
|   params.drvexam = params.drvexam ?? {};
 | |
|   params.drvexam.zp = params.drvexam.zp === undefined ? undefined : encodeURIComponent(params.drvexam.zp);
 | |
| 
 | |
|   const drvexamArr = Object.entries(params.drvexam)
 | |
|     .filter((item: [string, string]) => item[1] != undefined)
 | |
|     .map((item: [string, object]) => `<${item[0]}>${item[1]}</${item[0]}>`)
 | |
| 
 | |
|   if (filePath) {
 | |
|     const fileUtil = new FileUtils(context);
 | |
|     await fileUtil.initFolder(filePath);
 | |
|     let obj: WuxiExamType = {
 | |
|       xtlb: params.xtlb,
 | |
|       jkxlh: params.jkxlh,
 | |
|       jkid: params.jkid,
 | |
|       drvexam: {
 | |
|         zp: "",
 | |
| 
 | |
|       },
 | |
|     }
 | |
|     fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(obj) + `\n`);
 | |
|   }
 | |
|   dConsole.log(JudgeTag, "老监管", JGHOST)
 | |
|   //对象转换成xml
 | |
|   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>
 | |
|                             ${drvexamArr}
 | |
|                           </drvexam>
 | |
|                         </root>
 | |
|                       ]]>
 | |
|                       </UTF8XmlDoc>
 | |
|                     </writeObjectOut>
 | |
|                  </SOAP-ENV:Body>
 | |
|                </SOAP-ENV:Envelope>`,
 | |
|     method: http.RequestMethod.POST,
 | |
|     xml: true
 | |
|   },)
 | |
|   if (filePath) {
 | |
|     const fileUtil = new FileUtils(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: number
 | |
|   time: string
 | |
|   cardNo: string
 | |
|   examData: string
 | |
|   examStartTime: string
 | |
|   examEndTime: string
 | |
| }
 | |
| 
 | |
| // 过程文件上传
 | |
| export async function uploadExamProgressData(params: UploadExamProgressDataParams) {
 | |
|   const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
 | |
|   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 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<boolean>('singlePlay') || false
 | |
|   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: number
 | |
|   kskssj: string
 | |
| }
 | |
| 
 | |
| // 上传考试里程
 | |
| export async function uploadExamMileage(params: UploadExamMileage) {
 | |
|   // const singlePlay = globalThis.singlePlay
 | |
|   const singlePlay: boolean = AppStorage.get<boolean>('singlePlay') || false
 | |
| 
 | |
|   if (singlePlay) {
 | |
|     return
 | |
|   }
 | |
|   const time = 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<boolean>('singlePlay') || false
 | |
| //   if (singlePlay) {
 | |
| //     return
 | |
| //   }
 | |
| //   const paramsArrs = Reflect.ownKeys(params).map((key) => (`<${key}>${params[key]}</${key}>`))
 | |
| //   const time = 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
 | |
| //   })
 | |
| // }
 | |
| 
 | |
| 
 | |
| // 上传运行时常
 | |
| export async function uploadHarmonyLiCheng(data: object) {
 | |
|   return request<object>({
 | |
|     url: '/der2/services/data/harmonyLiCheng.ws',
 | |
|     data,
 | |
|     method: http.RequestMethod.POST,
 | |
|     xml: false
 | |
|   })
 | |
| }
 | |
| 
 | |
| 
 | |
| function validateIP(path: string) {
 | |
|   // const regex = /(\w+):\/\/([\d.]+)(:\d+)?/;
 | |
|   const regex = new RegExp("(\\w+):\\/\\/([\\d.]+)(:\\d+)?");
 | |
|   const result = path.match(regex);
 | |
|   return result ? result[0] : null;
 | |
| }
 |