package com.mortals.xhx.daemon.task;

import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.utils.ServletUtils;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.module.door.model.DoorEntity;
import com.mortals.xhx.module.door.model.DoorQuery;
import com.mortals.xhx.module.door.service.DoorService;
import com.mortals.xhx.module.hik.face.model.req.img.ImgReq;
import com.mortals.xhx.module.hik.face.service.IHikFaceService;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.model.StaffQuery;
import com.mortals.xhx.module.staff.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 同步员工的证件照片。
 */
@Slf4j
@Service("SyncRegisterUserPicTask")
public class SyncRegisterUserPicTaskImpl implements ITaskExcuteService {

    @Autowired
    private UploadService uploadService;
    @Autowired
    private IHikFaceService hikFaceService;
    @Autowired
    private StaffService staffService;

    @Value("${hik.host:}")
    protected String hikhost;

    @Autowired
    private DoorService doorService;


    @Override
    public void excuteTask(ITask task) throws AppException {
        log.info("同步员工照片任务");
        if (!ObjectUtils.isEmpty(hikhost)) {
            staffService.syncRegisterUsersPhotos();
        } else {
            List<DoorEntity> doorEntities = doorService.find(new DoorQuery());
            for (DoorEntity doorEntity : doorEntities) {
                //todo 直连设备获取员工照片
            }
        }
        log.info("同步员工任务照片完成");

    }

    @Override
    public void stopTask(ITask task) throws AppException {

    }
}
