118 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			118 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'
 | 
						|
import promptAction from '@ohos.promptAction'
 | 
						|
import fileAccess from '@ohos.file.fileAccess'
 | 
						|
import common from '@ohos.app.ability.common'
 | 
						|
import Want from '@ohos.app.ability.Want'
 | 
						|
import fs from '@ohos.file.fs'
 | 
						|
import FileUtil from '../../../common/utils/File'
 | 
						|
import {getCurrentTime} from '../../../common/utils/tools'
 | 
						|
 | 
						|
interface StuInfo{
 | 
						|
  name:string
 | 
						|
  lsh:string
 | 
						|
  idCard:string
 | 
						|
}
 | 
						|
 | 
						|
const LOGTAG = 'LOGTAG'
 | 
						|
export default class FileLog {
 | 
						|
 | 
						|
  //后续文件路径待替换
 | 
						|
  private fileUtil: FileUtil
 | 
						|
  private stuInfo: StuInfo
 | 
						|
  public folderPath: string
 | 
						|
 | 
						|
  constructor(context) {
 | 
						|
    const fileUtil = new FileUtil(context)
 | 
						|
    this.fileUtil = fileUtil
 | 
						|
  }
 | 
						|
 | 
						|
  // 设置文件夹
 | 
						|
  public initFileLogo = async (stuInfo:StuInfo) => {
 | 
						|
    const {fileUtil,setExamLineData} = this
 | 
						|
    const {name,lsh,idCard} = stuInfo;
 | 
						|
    this.stuInfo = stuInfo;
 | 
						|
    const time = await getCurrentTime()
 | 
						|
    const date = time.split(' ')[0].split('-').join('_')
 | 
						|
    const hourTime = time.split(' ')[1].split(':').join('_')
 | 
						|
    const folderPath = await fileUtil.initFolder(`/logs/${date}/${date}_${hourTime}_${lsh}_${idCard}_${name}`);
 | 
						|
    this.folderPath = folderPath;
 | 
						|
  }
 | 
						|
 | 
						|
  // 过程文件数据
 | 
						|
  public setExamProgressData = async (str:Object) => {
 | 
						|
    const {fileUtil,folderPath} = this;
 | 
						|
    await fileUtil.editFile(`${folderPath}/exam_progress_data.txt`,JSON.stringify(str));
 | 
						|
  }
 | 
						|
 | 
						|
  // 无锡所接口数据
 | 
						|
  public setExamJudgeWuxiData = async (str) => {
 | 
						|
    const {fileUtil,folderPath} = this;
 | 
						|
    await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`,str);
 | 
						|
  }
 | 
						|
 | 
						|
  // 无锡所过程数据
 | 
						|
  public setExamJudgeWuxiProgressData = async (str)=>{
 | 
						|
    const {fileUtil,folderPath} = this;
 | 
						|
    await fileUtil.editFile(`${folderPath}/wuxi_progress_data.txt`,str);
 | 
						|
  }
 | 
						|
 | 
						|
  // plc文件数据
 | 
						|
  public setPlcProgressData = async (str:Object) => {
 | 
						|
    const {fileUtil,folderPath} = this;
 | 
						|
    await fileUtil.editFile(`${folderPath}/plc_data.txt`,JSON.stringify(str));
 | 
						|
  }
 | 
						|
 | 
						|
  // 过程评判json数据
 | 
						|
  public setExamJudgeData = async (str:Object) => {
 | 
						|
    const {fileUtil,folderPath} = this;
 | 
						|
    await fileUtil.editFile(`${folderPath}/judge_exam_data.txt`,JSON.stringify(str));
 | 
						|
  }
 | 
						|
 | 
						|
  // 过程评判回调数据
 | 
						|
  public setExamJudgeCallbackData = async (str:string) => {
 | 
						|
    const {fileUtil,folderPath} = this;
 | 
						|
    await fileUtil.editFile(`${folderPath}/judge_progress_callback_data.txt`,str);
 | 
						|
  }
 | 
						|
 | 
						|
  // 过程评判日志调数据
 | 
						|
  public setExamJudgeLogData = async (str:string) => {
 | 
						|
    const {fileUtil,folderPath} = this;
 | 
						|
    await fileUtil.editFile(`${folderPath}/judge_log_data.txt`,str);
 | 
						|
  }
 | 
						|
 | 
						|
  // 无锡所轨迹数据
 | 
						|
  public setExamLineData = async (plcStr) => {
 | 
						|
    const {fileUtil,folderPath} = this;
 | 
						|
    const plcData = plcStr.split(',');
 | 
						|
    const time = await getCurrentTime();
 | 
						|
 | 
						|
    const lineData = [
 | 
						|
    /*帧头*/ time,
 | 
						|
      /*卫星时间*/time,
 | 
						|
      /*经度*/ plcData[95],
 | 
						|
      /*纬度*/ plcData[95],
 | 
						|
      /*高度*/ plcData[86],
 | 
						|
      /*方位角*/ 0,
 | 
						|
      /*俯仰角*/ plcData[91],
 | 
						|
      /*速度角*/'',
 | 
						|
      /*速度*/  plcData[97],
 | 
						|
      /*横滚*/'',
 | 
						|
      /*卫星定位状态*/'',
 | 
						|
      /*卫星定向状态*/'',
 | 
						|
      /*前天线可用星数*/'',
 | 
						|
      /*后天线可用星数*/'',
 | 
						|
      /*东向位置坐标*/'',
 | 
						|
      /*北向位置坐标*/'',
 | 
						|
      /*天向位置坐标*/'',
 | 
						|
      /*东向速度*/'',
 | 
						|
      /*北向速度*/'',
 | 
						|
      /*评判信号1*/[plcData[14],plcData[19],plcData[5],'',plcData[2],plcData[3],plcData[7],plcData[8],plcData[13],plcData[12],plcData[17],'',plcData[4],plcData[11],plcData[20],plcData[9],0].join(','),
 | 
						|
      /*评判信号2*/['',plcData[28],'','',plcData[10],'','','','','','','','','','','','',''].join(','),
 | 
						|
      /*发动机转速*/ plcData[25],
 | 
						|
      /*结束符*/ time,
 | 
						|
    ];
 | 
						|
 | 
						|
    await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`,JSON.stringify(lineData));
 | 
						|
  };
 | 
						|
}
 |