package com.xjrsoft.module.liteflow.node;

import cn.hutool.core.convert.Convert;
import com.xjrsoft.module.hikvision.mapper.HikvisionDataMapper;
import com.xjrsoft.module.hikvision.util.FaceImportUtil;
import com.xjrsoft.module.personnel.entity.StundentFaceProcess;
import com.xjrsoft.module.personnel.service.IStundentFaceProcessService;
import com.xjrsoft.module.teacher.mapper.FaceImportMapper;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 导出学生照片到海康平台
 */
@Component("import_student_face_node")
public class ImportStudentFaceNode extends NodeComponent {
    @Autowired
    private IStundentFaceProcessService stundentFaceProcessService;

    @Autowired
    private HikvisionDataMapper hikvisionDataMapper;

    @Autowired
    private FaceImportMapper faceImportMapper;

    @Override
    public void process() throws Exception {
        // 获取表单中数据编号
        Map<String, Object> params = this.getFirstContextBean();
        Object value = util.getFormDatKey(params,"id");
        Long formId = Convert.toLong(value);
        if (formId != null) {
            String fileUrl = faceImportMapper.GetStudentHikvisionImgById(formId);
            // 数据处理
            StundentFaceProcess dataObj = stundentFaceProcessService.getById(formId);
            dataObj.setStatus(1);
            dataObj.setExamStatus(1);
            String result = FaceImportUtil.ImportStudentFace(hikvisionDataMapper.getStudentHikvisionId(dataObj.getUserId()), fileUrl);
            dataObj.setHikvisionResult(result);
            stundentFaceProcessService.updateById(dataObj);


        }
    }
}

