package com.mortals.xhx.busiz.web;

import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.module.hik.event.model.req.callback.EventReq;
import com.mortals.xhx.module.hik.event.service.IHikEventService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("hik")
public class HikCallbackController {

    @Autowired
    private IHikEventService hikEventService;

    @PostMapping("eventRcv")
    @UnAuth
    public Rest<String> receivePlanMessage(@RequestBody EventReq req) {
        //log.info("【接收人脸计划事件数据】【请求体】--> {}", JSON.toJSONString(req));
        //    EventReq eventReq = JSON.parseObject(req, EventReq.class);
        try {
            Rest<String> rest = hikEventService.handleEvent(req);
            return Rest.ok(rest.getMsg());

        } catch (Exception e) {
            log.error("接收数据失败", e);
            return Rest.fail();
        }
    }

}
