package com.xjrsoft.module.liteflow.node;

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

import java.util.Map;

/**
 * 导出老师照片到海康平台
 */
@Component("import_teacher_face_node")
public class ImportTeacherFaceNode extends NodeComponent {

    @Autowired
    private ITeacherFaceProcessService teacherFaceProcessService;

    @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.GetTeacherHikvisionImgById(formId);

            // 数据处理
            TeacherFaceProcess dataObj = teacherFaceProcessService.getById(formId);
            dataObj.setStatus(1);
            dataObj.setExamStatus(1);
            String reslut = FaceImportUtil.ImportTeacherFace(hikvisionDataMapper.getTeacherHikvisionId(dataObj.getUserId()), fileUrl);
            dataObj.setHikvisionResult(reslut);
            teacherFaceProcessService.updateById(dataObj);
        }
    }
}
