package com.mortals.xhx.module.hik.face.service.impl;

import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.hik.face.model.FaceGroupEntity;
import com.mortals.xhx.module.hik.face.model.req.group.FaceGroupReq;
import com.mortals.xhx.module.hik.face.model.rsp.group.FaceGroupDataInfo;
import com.mortals.xhx.module.hik.face.service.IHikFaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.hik.face.dao.FaceGroupDao;
import com.mortals.xhx.module.hik.face.service.FaceGroupService;

import java.util.Date;

/**
 * FaceGroupService
 * 人脸分组信息 service实现
 *
 * @author zxfei
 * @date 2023-04-15
 */
@Service("faceGroupService")
public class FaceGroupServiceImpl extends AbstractCRUDServiceImpl<FaceGroupDao, FaceGroupEntity, Long> implements FaceGroupService {

    @Autowired
    private IHikFaceService hikFaceService;

    @Override
    public Rest<FaceGroupEntity> saveFaceGroupToHik(FaceGroupReq faceGroupReq) {
        Rest<FaceGroupDataInfo> faceGroupRest = hikFaceService.faceGroupSingleAdd(faceGroupReq);
        if (faceGroupRest.getCode() == YesNoEnum.YES.getValue()) {
            FaceGroupEntity groupEntity = new FaceGroupEntity();
            groupEntity.initAttrValue();
            groupEntity.setName(faceGroupReq.getName());
            groupEntity.setDescription(faceGroupReq.getDescription());
            groupEntity.setIndexCode(faceGroupRest.getData().getIndexCode());
            groupEntity.setCreateTime(new Date());
            groupEntity.setCreateUserId(1L);
            groupEntity.setCreateUserName("admin");
            this.save(groupEntity);
            return Rest.ok(groupEntity);
        }
        return Rest.fail();
    }
}