package com.zhongzheng.controller.face;

import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.face.bo.FaceVo;
import com.zhongzheng.modules.face.service.IFaceService;
import com.zhongzheng.modules.polyv.service.IPolyvVideoService;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 人脸核身Controller
 *
 * @author hjl
 * @date 2021-06-18
 */
@Api(value = "人脸核身", tags = {"人脸核身"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/face")
public class FaceController extends BaseController {

    private final IFaceService iFaceService;

    private final WxTokenService wxTokenService;

    @ApiOperation("获取识别凭证")
    @GetMapping("/certification/BizToken")
    public AjaxResult<FaceVo> getBizToken() throws Exception {
        FaceVo face = iFaceService.getFaceDetectAuth("0");
        return AjaxResult.success(face);
    }

    @ApiOperation("获取识别结果")
    @GetMapping("/certification/DetectInfo/{bizToken}")
    public AjaxResult getDetectInfo(@PathVariable("bizToken") String bizToken) throws Exception {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        iFaceService.getDetectInfo(bizToken,loginUser.getUser().getUserId());
        return AjaxResult.success();
    }

    @ApiOperation("获取人照识别凭证")
    @GetMapping("/certification/PicBizToken")
    public AjaxResult<FaceVo> getPicBizToken() throws Exception {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        FaceVo face = iFaceService.getPicFaceDetectAuth("1",loginUser.getUser().getUserId());
        return AjaxResult.success(face);
    }

    @ApiOperation("获取人照识别结果")
    @GetMapping("/certification/PicDetectInfo/{bizToken}")
    public AjaxResult<Integer> getPicDetectInfo(@PathVariable("bizToken") String bizToken) throws Exception {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        Integer result = iFaceService.getPicDetectInfo(bizToken,loginUser.getUser().getUserId());
        return AjaxResult.success(result);
    }
}
