subject-two/entry/src/main/ets/pages/compontents/judge/BoardPrePareSetPopup.ets

609 lines
19 KiB
Plaintext
Raw Normal View History

2025-04-09 09:28:18 +08:00
import { JudgeConfig } from '../../judgeSDK/utils/judgeConfig';
2025-03-26 13:43:47 +08:00
2024-07-05 09:34:03 +08:00
import common from '@ohos.app.ability.common';
import VoiceAnnounce from '../../judgeSDK/utils/voiceAnnouncements';
import { MarkRule } from '../../judgeSDK/api/judgeSDK.d';
2025-02-19 13:24:07 +08:00
import { writeObjectOut } from '../../../api/judge';
2024-07-31 13:47:40 +08:00
import JudgeTask from '../../judgeSDK/utils/judgeTask';
import FilePhoto from '../../judgeSDK/utils/filePhoto';
import { CarInfoType, MASYSSETTableType } from '../../../model';
import { GetCurrentTime } from '../../../utils/Common';
2025-03-26 13:43:47 +08:00
import FileUtils from '../../../utils/FileUtils';
import { GetSyncData } from '../../../utils/table/Operation';
2024-07-05 09:34:03 +08:00
interface SEL {
fontColor: string
bgColor: string
}
2024-07-31 13:47:40 +08:00
//考前模拟人工扣分
2024-07-05 09:34:03 +08:00
@Component
export default struct DeductedPopup {
@State name: string = ''
@State idCard: string = ''
@State lsh: string = ''
@State kszp: string = ''
@State ksdd: string = ''
@State kssycs: string = ''
@State kslx: string = ''
2024-07-31 13:47:40 +08:00
@State ksxl: string = ''
@State score: number = 100;
@State judgeConfigObj: { [k: string]: any } = {}
2024-07-05 09:34:03 +08:00
@State kfdmArr: {
xmdm: number,
kfdm: string,
2024-07-31 13:47:40 +08:00
markreal: number,
markcatalog: string
2025-02-19 13:24:07 +08:00
score: number
2024-07-05 09:34:03 +08:00
}[] = []
//开始考试前判绕车一周评判是否开启
@State isOpen: boolean = false
//监管序列号
@State serialNumber: number = 0;
@State examSubject: number = 2;
@State markRuleListObj: MarkRule = {}
2024-12-05 18:31:06 +08:00
@State fontSize: number = 28
2024-07-05 09:34:03 +08:00
@State unselected: SEL = { fontColor: '#000000', bgColor: '#CCC4B8' }
@State selected: SEL = { fontColor: '#FFAD33', bgColor: '#26231E' }
@State currentIndex: number = 0
@State currentPageIndex: number = 0
//通用评判扣分
@State currentUniversalPageIndex: number = 0;
@State universalMarkRules: MarkRule[] = []
@State manualMarkRules: MarkRule[] = []
@State lineBg: Array<string> = ['#4D4136', '#26231E']
@State selectedLine: number = undefined
2025-02-19 13:24:07 +08:00
@State carInfo: CarInfoType = {
2025-02-18 13:43:20 +08:00
carId: '',
examinationRoomId: '',
plateNo: '',
isNeedCheck: '',
2025-02-19 13:24:07 +08:00
examSubject: '',
2025-02-18 13:43:20 +08:00
}
2025-02-13 15:30:48 +08:00
@State singlePlay: boolean = false
2024-07-05 09:34:03 +08:00
@State selectedLineStyle: SEL = {
fontColor: '#FFF',
bgColor: '#B36E00'
}
private context = getContext(this) as common.UIAbilityContext;
private judgeTask: JudgeTask
private filePhoto: FilePhoto
2025-02-19 13:24:07 +08:00
// 过程照片拍照
getPhoto = async (empty?: boolean) => {
//单机模式返回空照片
if (this.singlePlay) {
return ''
} else {
const photoBase64: string = await this.filePhoto.getPhoto();
2025-02-19 13:24:07 +08:00
return photoBase64
}
}
private avPlayer: VoiceAnnounce
2024-07-05 09:34:03 +08:00
2024-07-31 13:47:40 +08:00
async aboutToAppear() {
2025-03-26 14:48:56 +08:00
this.carInfo = AppStorage.get<CarInfoType>('carInfo')
this.singlePlay = AppStorage.get<boolean>('singlePlay')
this.avPlayer = new VoiceAnnounce(this.context);
2024-07-31 13:47:40 +08:00
this.judgeTask = new JudgeTask();
const mediaTest = new FilePhoto(this.context);
this.filePhoto = mediaTest
2024-07-05 09:34:03 +08:00
//上车准备
// this.universalMarkRules = this.markRules.filter(item => this.currentItems.includes(item.itemno+''))
// const { isTrajectoryOpen } = judgeConfig;
2025-04-09 09:28:18 +08:00
if (JudgeConfig.isTrajectoryOpen) {
2024-07-31 13:47:40 +08:00
await this.initDb()
2024-07-05 09:34:03 +08:00
} else {
2024-07-31 13:47:40 +08:00
await this.initSysset()
await this.initMarkRules()
await this.initStudent()
2024-07-05 09:34:03 +08:00
}
2024-07-31 13:47:40 +08:00
// const {judgeTask} = this;
// judgeTask.addTask(async () => {
// await this.beginProject();
// }, { isDelay: true })
// judgeTask.addTask(async () => {
// await this.uploadProgressPhoto();
// }, { isDelay: true })
2024-07-05 09:34:03 +08:00
}
//本地数据初始化
async initDb() {
// const { isTrajectoryOpen, trajectoryPath } = judgeConfig
2025-02-19 13:24:07 +08:00
const examSubject = this.carInfo.examSubject;
2024-07-05 09:34:03 +08:00
//轨迹回放读取 systemparam表、markrule表
2025-03-26 13:43:47 +08:00
const fileUtil = new FileUtils(this.context);
2025-04-09 09:28:18 +08:00
const folderPath = await fileUtil.initFolder(JudgeConfig.trajectoryPath);
2024-07-05 09:34:03 +08:00
const str = await fileUtil.readFile(folderPath);
const strArr = str.split('\n');
// const [initData, beginData] = [strArr[0], strArr[1]];
const initData = strArr[0];
const beginData = strArr[1];
// TODO 补全类型
const initDataObj: ESObject = JSON.parse(initData);
2025-04-09 09:28:18 +08:00
this.examSubject = Number(JudgeConfig.isTrajectoryOpen ? (initDataObj.kskm * 1) : examSubject);
2024-07-05 09:34:03 +08:00
await this.initMarkRules(initDataObj.mark);
await this.initSysset(initDataObj.sysset);
await this.initStudent()
}
2024-07-31 13:47:40 +08:00
// 扣分操作
async pointsDedute() {
const index = this.currentIndex ? this.currentUniversalPageIndex : this.currentPageIndex;
const mark = this.universalMarkRules[index * 7 + this.selectedLine];
2025-02-19 13:24:07 +08:00
const { judgeConfigObj, kssycs, avPlayer, judgeTask } = this;
2024-11-26 15:35:05 +08:00
this.kfdmArr.push({
xmdm: 1,
kfdm: mark.markserial,
markreal: mark.markreal,
2025-02-19 13:24:07 +08:00
markcatalog: mark.markcatalog,
score: mark.score
2024-11-26 15:35:05 +08:00
})
2024-07-31 13:47:40 +08:00
const kfdmArr = this.kfdmArr
//计算总扣分
let score = kfdmArr.reduce((p, n) => {
p += n.markreal * 1
return p
}, 0);
this.score = score
this.confirmMark(this.kfdmArr.map((kf) => ({
xmdm: kf.xmdm,
kfdm: kf.kfdm,
})))
2025-04-09 09:28:18 +08:00
if (judgeConfigObj['418'] == '1' || JudgeConfig.kfVoiceOpen) {
2025-02-19 13:24:07 +08:00
avPlayer.playAudio([`voice/${mark.markcatalog}.mp3`, `voice/mark_${Math.abs(mark.score)}.mp3`], false, () => {
2024-07-31 13:47:40 +08:00
this.closePopup(true)
});
return
}
2024-09-03 19:28:07 +08:00
this.closePopup();
2024-07-31 13:47:40 +08:00
return;
if (score < 90) {
this.closePopup(true)
avPlayer.playAudio(['voice/exam_waiting.mp3', `voice/kfdesc.mp3`])
judgeTask.addTask(async () => {
//扣分
await this.kfFn();
}, { isDelay: true })
judgeTask.addTask(async () => {
//项目结束
await this.endProject();
}, { isDelay: true })
judgeTask.addTask(async () => {
//结束考试
await this.endFn()
}, { isDelay: true })
}
;
2025-02-19 13:24:07 +08:00
let voiceURL =
score < 90 ? `voice/${kssycs == '1' ? 'exam_no_pass_finish' : 'exam_no_pass'}.mp3` : 'voice/exam_pass.mp3'
2024-07-31 13:47:40 +08:00
let kfScore = 0;
if (kfdmArr.length) {
kfdmArr.forEach((kf, index) => {
kfScore += Math.abs(Number(kf.markreal));
if (kfScore <= 100) {
judgeTask.addTask(() => {
if (index === kfdmArr.length - 1) {
avPlayer.playAudio([`voice/${kf.markcatalog}.mp3`, voiceURL], false, () => {
this.endLoading(true)
})
} else {
avPlayer.playAudio([`voice/${kf.markcatalog}.mp3`])
}
})
}
})
}
this.confirmMark(this.kfdmArr.map((kf) => ({
xmdm: kf.xmdm,
kfdm: kf.kfdm,
})))
}
//项目开始
async beginProject() {
//项目开始 //过程照片 //扣分 //结束考试
2025-02-19 13:24:07 +08:00
const carInfo: CarInfoType = this.carInfo;
const { examSubject, plateNo } = carInfo;
const { serialNumber, lsh, idCard, ksxl, kslx, ksdd } = this
const time = GetCurrentTime();
2024-07-31 13:47:40 +08:00
const beginData = {
2025-02-19 13:24:07 +08:00
xtlb: '17',
jkxlh: serialNumber,
jkid: '17C52',
2024-07-31 13:47:40 +08:00
drvexam: {
// 考试科目 身份证号码
lsh,
kskm: examSubject,
sfzmhm: idCard,
ksxm: '40100',
ksxl,
kchp: decodeURI(plateNo),
ksdd: decodeURI(ksdd),
kslx: decodeURI(kslx) || '',
kssj: time
},
}
const code = await writeObjectOut(beginData)
//TODO code待处理
2024-08-12 10:19:31 +08:00
// if (code == 1) {
//
// }
2024-07-31 13:47:40 +08:00
}
//过程照片
async uploadProgressPhoto() {
2025-02-19 13:24:07 +08:00
const { serialNumber, lsh, idCard, ksdd, kfdmArr, getPhoto } = this;
2025-02-13 15:30:48 +08:00
const carInfo = this.carInfo;
2025-02-19 13:24:07 +08:00
const { examSubject, plateNo, carNo } = carInfo;
const time = GetCurrentTime();
2024-07-31 13:47:40 +08:00
console.info('surenjun uploadProgressPhoto',)
const photoBase64 = await getPhoto()
const photoData = {
2025-02-19 13:24:07 +08:00
xtlb: '17',
jkxlh: serialNumber,
jkid: '17C54',
2024-07-31 13:47:40 +08:00
drvexam: {
lsh,
kskm: examSubject,
ksxm: '40100',
sfzmhm: idCard,
kchp: decodeURI(plateNo),
zpsj: time,
// zp: encodeURIComponent(photoBase64),
zp: photoBase64,
cs: 0,
ksdd: decodeURI(ksdd)
}
};
const code = await writeObjectOut(photoData);
console.info('surenjun uploadProgressPhoto end',)
}
// 扣分
async kfFn() {
2025-02-19 13:24:07 +08:00
const { serialNumber, lsh, idCard, ksdd, kfdmArr } = this;
2024-07-31 13:47:40 +08:00
const kfLen = kfdmArr.length;
const kf = kfdmArr[kfLen -1];
2025-02-19 13:24:07 +08:00
const carInfo: CarInfoType = this.carInfo;
const { examSubject } = this.carInfo;
const time = GetCurrentTime();
2024-07-31 13:47:40 +08:00
const kfData = {
2025-02-19 13:24:07 +08:00
xtlb: '17',
jkxlh: serialNumber,
jkid: '17C53',
2024-07-31 13:47:40 +08:00
drvexam: {
lsh,
kskm: examSubject,
// 通用评判科二10000科三30000
ksxm: 40100,
kfxm: kf.markcatalog,
kfxmmx: `${'1'},${kf.kfdm}`,
sfzmhm: idCard,
kchp: decodeURI(carInfo.plateNo),
kffs: 2,
ksdd: decodeURI(ksdd),
kfsj: time
}
}
const code = await writeObjectOut(kfData);
}
// 项目结束
async endProject() {
2025-02-13 15:30:48 +08:00
const carInfo = this.carInfo;
2025-02-19 13:24:07 +08:00
const { examSubject, plateNo, carNo } = carInfo;
const { lsh, idCard, serialNumber, ksdd, kslx, ksxl, } = this;
const time = GetCurrentTime();
2024-07-31 13:47:40 +08:00
const endProjectData = {
2025-02-19 13:24:07 +08:00
xtlb: '17',
jkxlh: serialNumber,
jkid: '17C55',
2024-07-31 13:47:40 +08:00
drvexam: {
lsh,
kskm: examSubject,
sfzmhm: idCard,
ksxm: '40100',
czlx: '1',
ksxl,
kchp: decodeURI(plateNo),
ksdd: decodeURI(ksdd),
kslx: encodeURI(kslx) || '',
jssj: time
}
}
const code = await writeObjectOut(endProjectData);
}
//考试结束
async endFn() {
2025-02-19 13:24:07 +08:00
const { serialNumber, lsh, idCard, score, getPhoto } = this;
const carInfo: CarInfoType = this.carInfo;
const { examSubject, plateNo } = carInfo;
const time = GetCurrentTime();
2024-07-31 13:47:40 +08:00
const photoBase64 = await getPhoto();
const endData = {
2025-02-19 13:24:07 +08:00
xtlb: '17',
jkxlh: serialNumber,
jkid: '17C56',
2024-07-31 13:47:40 +08:00
drvexam: {
lsh,
kchp: decodeURI(plateNo),
kskm: examSubject,
sfzmhm: idCard,
// zp: encodeURIComponent(photoBase64),
zp: photoBase64,
jssj: time,
kscj: (score * 1) > 0 ? score : 0,
kslc: 0,
dwlc: '',
}
}
const code = await writeObjectOut(endData);
}
2024-07-05 09:34:03 +08:00
//获取sysset表数据
async initSysset(sysset?: MASYSSETTableType[]) {
const syssetParams = sysset || await GetSyncData<MASYSSETTableType>('MA_SYSSET');
2024-07-31 13:47:40 +08:00
console.info('surenjun syssetParams', JSON.stringify(syssetParams));
2024-07-05 09:34:03 +08:00
syssetParams.forEach(sys => {
//监管序列号
2024-07-10 19:39:13 +08:00
if (sys.v_no == '901') {
2024-07-05 09:34:03 +08:00
this.serialNumber = sys.v_value || '123456'
}
//364 绕车一周评判时机(1-开始考试后判 2-开始考试前判)
2024-07-10 19:39:13 +08:00
if (sys.v_no == '364') {
2024-07-05 09:34:03 +08:00
const isOpen = sys.v_value == 2
if (isOpen) {
this.avPlayer.playAudio(['voice/上车准备.mp3'])
}
}
2024-07-31 13:47:40 +08:00
this.judgeConfigObj[sys.v_no] = decodeURIComponent(sys.v_value)
2024-07-05 09:34:03 +08:00
})
}
//获取markrule表数据
async initMarkRules(markRules ?: MarkRule[]) {
const markRuleParams = markRules || (await getSyncData('MA_MARKRULE') as MarkRule[])
markRuleParams.forEach(mark => {
const tempObj = {
itemno: mark.itemno * 1,
markcatalog: mark.markcatalog,
markshow: decodeURI(mark.markshow),
markreal: mark.markreal * 1,
markstandard: mark.markstandard * 1,
markserial: mark.markserial,
kfxh: mark.kfxh,
OnlyOneKind: mark.onlyoneid * 1,
NoCancelId: mark.nocancelid * 1,
GPS_SID: mark.gps_sid == 0 ? false : true
}
2024-07-10 19:39:13 +08:00
if (mark.itemno == 1 && Number(mark.markserial) > 100 && Number(mark.markserial) < 200) {
2024-07-05 09:34:03 +08:00
this.markRuleListObj[`${mark.itemno}_${mark.markserial}`] = {
...tempObj,
markserial: mark.markserial,
};
this.universalMarkRules.push(tempObj)
}
})
}
// 获取考生信息
async initStudent() {
const students = await getSyncData('USER')
const stuInfo = students[0] || {};
2024-07-31 13:47:40 +08:00
2025-02-19 13:24:07 +08:00
const { xm, sfzmhm, lsh, kszp, ksdd, kssycs, kslx, ksxl } = stuInfo;
2024-07-05 09:34:03 +08:00
this.name = xm || '测试考生';
this.idCard = sfzmhm || '01234567891010';
this.lsh = lsh;
this.kszp = kszp;
this.ksdd = ksdd;
this.kssycs = kssycs;
this.kslx = kslx;
2024-07-31 13:47:40 +08:00
this.ksxl = ksxl;
2024-07-05 09:34:03 +08:00
}
//上一页 下一页
goPage(typeIndex) {
const currentIndex = this.currentIndex
if (currentIndex) {
//通用评判
typeIndex ? (this.currentUniversalPageIndex += 1) : (this.currentUniversalPageIndex -= 1)
} else {
typeIndex ? (this.currentPageIndex += 1) : (this.currentPageIndex -= 1)
}
this.selectedLine = -1
}
//选中扣分项
getSelectedLine(index) {
2025-02-19 13:24:07 +08:00
const { selectedLine, selectedLineStyle, lineBg } = this;
2024-07-05 09:34:03 +08:00
if (selectedLine === index) {
return selectedLineStyle.bgColor
}
if (index % 2 === 0) {
return lineBg[0]
} else {
return lineBg[1]
}
}
//获取当前页的数据
getCurrentMarkRuleList() {
2025-02-19 13:24:07 +08:00
const { currentIndex, currentUniversalPageIndex, currentPageIndex, universalMarkRules } = this;
2024-07-05 09:34:03 +08:00
if (currentIndex) {
//通用评判
return universalMarkRules.slice(currentUniversalPageIndex * 7, (currentUniversalPageIndex + 1) * 7)
} else {
return universalMarkRules.slice(currentPageIndex * 7, (currentPageIndex + 1) * 7)
}
}
build() {
Column() {
Column() {
Column() {
Row() {
Row() {
ForEach(['人工评判'], (text, index) => {
Row() {
Text(text)
.fontColor(index === this.currentIndex ? this.selected.fontColor : this.unselected.fontColor)
.fontSize(this.fontSize)
.fontWeight(500)
}
.width(180)
.height(70)
.backgroundColor(index === this.currentIndex ? this.selected.bgColor : this.unselected.bgColor)
.justifyContent(FlexAlign.Center)
.justifyContent(FlexAlign.Center)
.borderRadius({ topLeft: 20, topRight: 20 })
.margin({ right: 10 })
.onClick(() => {
this.currentIndex = index;
this.selectedLine = -1;
// if(index === 1) {
// this.universalMarkRules = this.markRules.filter(item => item.itemno == 20 )
// }else{
// this.universalMarkRules = this.markRules.filter(item => this.currentItems.includes(item.itemno+''))
// }
})
})
}
Row() {
if (
2025-02-19 13:24:07 +08:00
(Math.ceil(this.universalMarkRules.length / 7 - 1)) >=
(this.currentIndex ? this.currentUniversalPageIndex : this.currentPageIndex) &&
2024-07-05 09:34:03 +08:00
(this.currentIndex ? this.currentUniversalPageIndex : this.currentPageIndex) > 0
) {
Row() {
Row() {
2024-12-05 18:31:06 +08:00
}.width(40).height(36).backgroundImage($rawfile(`judge/km3/zuo_nor.png`)).margin({ left: 24, top: 4 })
2024-07-05 09:34:03 +08:00
Text('上一页') {
}.fontColor('#FFF').fontSize(this.fontSize)
}
.width(160)
.height(80)
.justifyContent(FlexAlign.Start)
.alignItems(VerticalAlign.Center)
.backgroundImage($rawfile(`judge/km3/button_nor.png`))
.backgroundImageSize({ width: '100%', height: '100%' })
.onClick(() => {
this.goPage(0)
})
}
if (
2025-02-19 13:24:07 +08:00
(Math.ceil(this.universalMarkRules.length / 7 - 1)) >
(this.currentIndex ? this.currentUniversalPageIndex : this.currentPageIndex)
2024-07-05 09:34:03 +08:00
) {
Row() {
Text('下一页') {
}.fontColor('#FFF').fontSize(this.fontSize).padding({ left: 30 })
Row() {
2024-12-05 18:31:06 +08:00
}.width(40).height(36).backgroundImage($rawfile(`judge/km3/you_nor.png`)).margin({ left: 4, top: 4 })
2024-07-05 09:34:03 +08:00
}
.width(160)
.height(80)
.justifyContent(FlexAlign.Start)
.alignItems(VerticalAlign.Center)
.backgroundImage($rawfile(`judge/km3/button_nor.png`))
.backgroundImageSize({ width: '100%', height: '100%' })
.onClick(() => {
this.goPage(1)
})
}
Row() {
Text('扣 分') {
}.fontColor('#FFF').fontSize(this.fontSize).padding({ left: 49 })
}
2024-12-05 18:31:06 +08:00
.width(180)
2024-07-05 09:34:03 +08:00
.height(80)
.justifyContent(FlexAlign.Start)
.alignItems(VerticalAlign.Center)
.backgroundImage($rawfile(`judge/km3/button_nor.png`))
.backgroundImageSize({ width: '100%', height: '100%' })
2024-07-31 13:47:40 +08:00
.onClick(async () => {
this.pointsDedute()
2024-07-05 09:34:03 +08:00
})
}
}.width('100%').justifyContent(FlexAlign.SpaceBetween)
Column() {
ForEach(this.getCurrentMarkRuleList(), (item, index) => {
Row() {
Text(`${item.markshow} (${item.markcatalog})`).fontColor('#FFF').fontSize(this.fontSize).fontWeight(500)
Row() {
Text(item.markreal + '').fontColor('#FFF').fontSize(this.fontSize).fontWeight(500)
}
}
.width('100%')
.height(75)
.justifyContent(FlexAlign.SpaceBetween)
.alignItems(VerticalAlign.Center)
.padding({ left: 20, right: 20 })
.backgroundColor(this.getSelectedLine(index))
.onClick(() => {
this.selectedLine = index
})
})
}
}
}
.width(1300)
.height(710)
2024-08-05 09:47:44 +08:00
.position({ x: '10%', y: '10%' })
2024-07-05 09:34:03 +08:00
.backgroundColor('#E6E3DF')
2025-02-19 13:24:07 +08:00
.padding({
top: 15,
bottom: 15,
left: 25,
right: 25
})
2024-07-05 09:34:03 +08:00
.borderRadius(20)
Row() {
}
.width(100)
.height(100)
.position({ y: '85%', x: '50%' })
.backgroundImage($rawfile('judge/km3/close_nor.png'))
.backgroundImageSize({ width: '100%', height: '100%' })
2024-07-31 13:47:40 +08:00
.onClick(async () => {
//没有扣分项目通过
this.closePopup(this.kfdmArr.length ? true : false)
2025-02-19 13:24:07 +08:00
// judgeTask.addTask(async () => {
// await this.endProject()
// }, { isDelay: true })
2024-07-31 13:47:40 +08:00
2024-07-05 09:34:03 +08:00
})
}.width('100%').height('100%').position({ y: 0 }).backgroundColor('rgba(0,0,0,0.7)')
}
2025-02-19 13:24:07 +08:00
private closePopup: Function = () => {
}
private confirmMark: Function = (itemno: number, serial: string) => {
}
private endLoading: Function = () => {
}
2024-07-05 09:34:03 +08:00
}